package com.she.olympic;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import ken.app.adapter.QueryMemberContentAdapter;
import ken.app.adapter.QueryPersonCouponAdapter;
import ken.app.adapter.QueryTreeAdapter;
import ken.app.adapter.SportBabyListAdapter;
import ken.app.adapter.TreeAllAdapter;
import ken.app.bean.CHTContentUploadBean;
import ken.app.bean.GetCameraBabyBean;
import ken.app.bean.GetStoreInfoBean;
import ken.app.bean.GuestContentUploadBean;
import ken.app.bean.GuestRecordUploadBean;
import ken.app.bean.MemberContentUploadBean;
import ken.app.bean.MemberGoodBean;
import ken.app.bean.MemberModifyNameBean;
import ken.app.bean.MemberSelfGetFruitBean;
import ken.app.bean.NewsListBean;
import ken.app.bean.TranBabySaveCodeBean;
import ken.app.bean.PersonalBean;
import ken.app.bean.QueryMemberContentBean;
import ken.app.bean.QueryPersonCouponBean;
import ken.app.bean.QueryPersonalBabyBean;
import ken.app.bean.TranBabyGetCodeBean;
import ken.app.bean.SportBabyListBean;
import ken.app.bean.TreeAllBean;
import ken.app.bean.TreeSingleBean;
import ken.app.bean.UpdPushTokenBean;
import ken.app.bean.VisitorGoodBean;
import ken.app.even.CHTContentUploadEvent;
import ken.app.even.CheckBabyLastmodifyEvent;
import ken.app.even.Event;
import ken.app.even.GetCameraBabyEvent;
import ken.app.even.GetStoreInfoEvent;
import ken.app.even.GetTreeAllEvent;
import ken.app.even.GuestContentUploadEvent;
import ken.app.even.GuestRecordUploadEvent;
import ken.app.even.KenEventManager;
import ken.app.even.LoginEvent;
import ken.app.even.MemberCanLikeEvent;
import ken.app.even.MemberContentUploadEvent;
import ken.app.even.MemberGoodEvent;
import ken.app.even.MemberModifyNameEvent;
import ken.app.even.MemberSelfGetFruitEvent;
import ken.app.even.NewsListEvent;
import ken.app.even.TranBabySaveCodeEvent;
import ken.app.even.QueryMemberContentEvent;
import ken.app.even.QueryPersonCouponEvent;
import ken.app.even.QueryPersonalBabyEvent;
import ken.app.even.QueryPersonalScoreEvent;
import ken.app.even.QueryTreeContentEvent;
import ken.app.even.SeverTimeEvent;
import ken.app.even.TranBabyGetCodeEvent;
import ken.app.even.ShareBabyListEvent;
import ken.app.even.SportBabyListEvent;
import ken.app.even.UpdPushTokenEvent;
import ken.app.even.VisitorCanLikeEvent;
import ken.app.even.VisitorGoodEvent;
import ken.app.even.iface.IEventCallback;
import ken.app.helper.Helper;

import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.ViewFlipper;

import com.adon.ar.test.ARExampleActivity;
import com.facebook.base.FacebookConnector;
import com.facebook.base.SessionEvents;
import com.woozzu.android.widget.RefreshableListView;
import com.woozzu.android.widget.RefreshableListView.OnRefreshListener;


public class TreeActivity extends Activity implements SensorEventListener {

	public static RelativeLayout toolBar;

	private ListView mPersonCouponListView, mPersonlContentListView, member_BabyList;
	private static RefreshableListView mTreeListView, mSingleTreeListView;
	private WebView infosView;
	// Cliff add
	private WebViewClient mWebViewClient = new WebViewClient() {
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			if (url.startsWith("tel")) {
				Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
				startActivity(callIntent);
				return true;
			}
			return false;
		}
	};

	/* flag */
	private boolean personalMsgPopisOpen = false;
	private boolean sportsmanMsgPopisOpen = false;
	private boolean giftMsgPopisOpen = false;
	private boolean loginInfoPageisOpen = false;

	/* Adpater */
	private TreeAllAdapter mTreeAllAdapter;
	private QueryTreeAdapter mMemberTreeAdapter;
	private QueryMemberContentAdapter mQueryMemberContentAdapter;
	private QueryPersonCouponAdapter mQueryPersonCouponAdapter;
	private SportBabyListAdapter mBabyListAdapter;

	/* ArrayList */
	private List<TreeAllBean> treeListData;// 加油樹ArrayList
	private List<TreeAllBean> canLikeTreeListData;// 尚可加油的選手ArrayList
	private List<TreeSingleBean> treeSingleListData;// 留言ArrayList
	private List<QueryMemberContentBean> memberContentData;// 會員留言ArrayList
	private List<QueryPersonCouponBean> quertPersonCouponData;// 會員個人優惠果實ArrayList
	private List<QueryPersonCouponBean> quertPersonCouponDataOfKind;// 分類會員個人優惠果實ArrayList
	private List<SportBabyListBean> sportBabyListDataOrg;// 原始寶寶列表ArrayList
	private List<SportBabyListBean> sportBabyListData;// 寶寶列表ArrayList
	private List<QueryPersonalBabyBean> queryPersonBabyData; // 會員寶寶列表ArrayList
	private List<GetCameraBabyBean> getCameraBabyData; // 可照集寶寶列表ArrayList
	private List<GetStoreInfoBean> storeInfoData;// 商家列表ArrayList
	private List<Integer> shareBabyListData; // 可交換的加油寶寶清單ArrayList
	private List<Integer> memberCanShareList; // 會員可分享加油寶寶清單ArrayList
	
	private int spinerselect = 0;
	private int personalfruit_count = 0;
	private int shareBabyCount = 0;
	
	private String shareBabyCode ;
	public static final String verCode = "1.5";
	private String NOfbAgain = "";//用來比對FB是否重複PO文
	
	// ===============Views==================
	private View member_WebView;
	private View layout1_a;
	private ViewFlipper member_Listview;
	private RelativeLayout treeSinglMsgPop, getGiftPage, member_MainLayout, more_Page, guestLogin, loginPage, multiLoginPage, layout1_b,
			msgadd, setting, infosViewPanel, loginInfoPage, memberFruitPage;
	private LinearLayout personal_MainLayout, bySharebabyPage, bySharebabyStep1Page, bySharebabyStep2Page, byGetbabyPage;
	// ======================================
	private ProgressDialog progressDialog = null;

	public static final boolean IS_DEBUG = true;
	
	public static final int TREEALL_ADAPTER_NOTIFY_DATA = 0;
	public static final int TREESINGLE_ADAPTER_NOTIFY_DATA = 1;
	public static final int MEMBERCONTENT_ADAPTER_NOTIFY_DATA = 2;
	public static final int PERSONCOUPON_ADAPTER_NOTIFY_DATA = 3;
	public static final int BABYLIST_ADAPTER_NOTIFY_DATA = 4;

	public static final int SETTEXT_FOR_TEXTVIEW = 20;
	public static final int SHOW_PERSONALFRUIT = 21;
	public static final int HIDE_PERSONALFRUIT = 22;

	public static final int FB_LIKE = 30;
	public static final int FB_WALLPOST = 31;

	public static final int SHOW_ALERTDIALOG_NOINTERNET = 40;
	public static final int SHOW_ALERTDIALOG_LOGINERROR = 41;
	public static final int SHOW_ALERTDIALOG_MSGADDBACK = 42;
	public static final int SHOW_ALERTDIALOG_MESSAGE = 43;
	public static final int SHOW_ALERTDIALOG_TO_LEVEL = 47;
	public static final int SHOW_TOAST = 44;
	public static final int MSGUPLOAD_ERROR = 45;
	public static final int MSG_SHOW = 46;
	public static final int SHOW_ALERTDIALOG_GETBABY = 48;

	public static final int INITLAYOUT2 = 50;
	public static final int SET_LAYOUTVIEW = 51;
	public static final int SHOW_GIFTLAYOUT = 52;
	public static final int INTO_SHAREBABYPAGE2 = 53;

	public static final int PROGRESSDIALOD_SHOW = 60;
	public static final int PROGRESSDIALOD_CANCEL = 61;

	public static final int ACCELEROMETER_DATA_GOT = 62; // message id for user
															// shake phone...

	public static final int GETBABY_RESULT = 99;

	public static final String URL_ADDMEMBER = "http://member.cht.com.tw/CHTRegi/mobile_reg_agreement.jsp";
	public static final String URL_FORGETPASS = "https://member.cht.com.tw/Users/m_forgot_password.jsp";
//	public static final String SEVER_API = "http://210.71.254.223";//正式機 210.65.46.111 210.71.254.223
	public static final String SEVER_API = "http://210.65.46.127";//測試機
	public String URL_NEWLIST = null;

	private boolean lockscreen = false;

	// =================================
	// private RelativeLayout getgift_BackgroundPanel = null;
	private BitmapDrawable layout1b_bmpDrawImg = null;
	private BitmapDrawable personal_bmpDrawImg = null;
	private BitmapDrawable morepage_bmpDrawImg = null;
	private BitmapDrawable memberMainLayout_bmpDrawImg = null;
	private BitmapDrawable layout1a_bmpDrawImg = null;
	private Bitmap loginInfoBgbitmap = null;
	private BitmapDrawable morepageBgbitmap = null;
	private Bitmap babyimg;
	// =================================

	// =============FB參數===============
	private FacebookConnector facebookConnector;
	private static boolean hasMessage = true;
	private String mUserName = ""; // full name
	// private String mUserfName; // first name
	// private String mUserlName; // last name
	// private String mUserID; // user id
	private static final String FACEBOOK_APPID = "289156174506272"; // PUT YOUR 289156174506272 215940998517680
																	// FACEBOOK
																	// APP ID
																	// HERE
	private static final String[] FACEBOOK_PERMISSION = new String[] { "user_photos", "publish_checkins", "publish_actions",
			"publish_stream" };
	// =================================

	// =============定位===============
	private LocationManager mLocationManager;
	private Location user_loc;
	// ===============================

	// =============Sensor===============
	private SensorManager mSensorManager = null; // SensorManager
	private Sensor mAccSensor = null; // Accelerometer
	private boolean isAccSensorSupported = false;
	private boolean isAccSensorEventListenerRegistered = false;
	private boolean isAccSensorShouldOn; // Set TRUE before we want to turn
											// sensor on, Set FALSE ...
	private int mShakeCount = 0; // one of x,y,z axis' accelerometer exceed 12,
									// then count will increase...

	// register : true ; unregister : false
	private void regAccSensorEventListener(boolean reg) {

		if (isAccSensorSupported == true) {
			if (reg == true && isAccSensorEventListenerRegistered == false) {
				mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_FASTEST);
				isAccSensorEventListenerRegistered = true;
				mShakeCount = 0;
			} else if (reg == false && isAccSensorEventListenerRegistered == true) {
				mSensorManager.unregisterListener(this, mAccSensor);
				isAccSensorEventListenerRegistered = false;
				mShakeCount = 0;
			}
		}
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		// TODO Auto-generated method stub
		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
			// All values are in SI units (m/s^2)
			// Log.d("ACC", "value 0 = " + event.values[0]);
			// Log.d("ACC", "value 1 = " + event.values[1]);
			// Log.d("ACC", "value 2 = " + event.values[2]);

			if (((event.values[0] > 12) || (event.values[0] > 12) || (event.values[0] > 12)) && (mShakeCount <= 5)) {

				mShakeCount++;

				if (mShakeCount == 5)
					mHandler.sendEmptyMessage(ACCELEROMETER_DATA_GOT);
			}
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		if (isAccSensorShouldOn)
			regAccSensorEventListener(true);
		
		if (mLocationManager != null) {
			user_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
			mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, new LocationListener() {
				@Override
				public void onStatusChanged(String provider, int status, Bundle extras) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
				}
				@Override
				public void onProviderEnabled(String provider) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
				}
				@Override
				public void onProviderDisabled(String provider) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
				}
				@Override
				public void onLocationChanged(Location location) {
					user_loc = location;
				}
			});
		}
		
		if (mLocationManager != null && user_loc == null) {
			user_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
			mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, new LocationListener() {
				@Override
				public void onStatusChanged(String provider, int status, Bundle extras) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
				}
				@Override
				public void onProviderEnabled(String provider) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
				}
				@Override
				public void onProviderDisabled(String provider) {
					user_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
				}
				@Override
				public void onLocationChanged(Location location) {
					user_loc = location;
				}
			});
		}
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();

		regAccSensorEventListener(false);
	}

	// Cliff add
	void setBackgroundLayout() {
		layout1a_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_02_1));
		layout1_a.setBackgroundDrawable(layout1a_bmpDrawImg);
		setLayoutView(layout1_a);
		addToolbar(TreeActivity.this, 0);
	}

	// Cliff add
	public void gotoTabTree() {
		/* popraw開啟時無法點擊 */
		if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
			((Olympic) this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
			cleanerLayout();
			setBackgroundLayout();

		}
	}

	// Cliff add
	public void gotoTabPresonal() {
		//
		KenEventManager.getInstance().setAccount("asd");
		KenEventManager.getInstance().setCHTsn(12345);
		KenEventManager.getInstance().setMembername("鍾阿憲");
		KenEventManager.getInstance().setNICKName("鍾阿憲");
		KenEventManager.getInstance().setUserType(1);

		/* popraw開啟時無法點擊 */
		if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
			cleanerLayout();
			/* 讀取sn來確定是否登入過 */
			if (KenEventManager.getInstance().getCHTsn() == 0) {

				/* 沒有sn未登入過 */
				loginPage = (RelativeLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_login_pertreepage, null);
				setLayoutView(loginPage);

				/* 登入背景說明頁 */
				showLoginInfo();

				/* 返回按鈕 */
				ImageView btn_back = (ImageView) findViewById(R.id.perpage_back);
				btn_back.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (!loginInfoPageisOpen) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									findViewById(R.id.perpage_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

							cleanerLayout();
							setBackgroundLayout();
							loginPage = null;
							((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
						}
					}
				});

				/* 加入會員按鈕 */
				ImageView btn_addMember = (ImageView) findViewById(R.id.perpage_addmember);
				btn_addMember.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
					}
				});
				/* 忘記密碼按鈕 */
				ImageView btn_forGetpass = (ImageView) findViewById(R.id.perpage_forgetpss);
				btn_forGetpass.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
					}
				});
				/* 登入按鈕 */
				ImageView btn_Login = (ImageView) findViewById(R.id.perpage_login);
				btn_Login.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// =============
						EditText account = (EditText) findViewById(R.id.perpage_account);
						EditText password = (EditText) findViewById(R.id.perpage_password);

						if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
						if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
						/* 判斷欄位是否有未填 */
						if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
								&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									password.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

							/* 轉轉 */
							Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
							mHandler.sendMessage(msg);

							PersonalBean.getInstance().setAccount(account.getText().toString());
							PersonalBean.getInstance().setPassword(password.getText().toString());
							LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
							loginEvent.addCallback(new IEventCallback() {
								@Override
								public void result(Event event, Object result) {

									Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
									mHandler.sendMessage(msg2);

									if (((PersonalBean) result).getChtsn() == 0 || ((PersonalBean) result).getUserType() == -1) {

										Message msg = mHandler.obtainMessage(MSG_SHOW, ((PersonalBean) result).getLoginMessage());
										mHandler.sendMessage(msg);
										if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
									} else {
										/* 儲存sn */
										KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
										/* 儲存帳號 */
										KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
										/* 儲存nickname */
										KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
										/* 儲存usertype */
										KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
										if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}
										/* 設定layout */
										loginPage = null;
										Message msg = new Message();
										msg.what = SET_LAYOUTVIEW;
										msg.arg1 = 1;
										mHandler.sendMessage(msg);

										/* 推播更新 */
										UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null,
												((Olympic) getApplicationContext()).getRegistrationID());
										updPushTokenEvent.addCallback(new IEventCallback() {

											@Override
											public void result(Event event, Object result) {
												if (result instanceof UpdPushTokenBean) {
													if (((UpdPushTokenBean) result).getResult() == 0000) {
														if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
														// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
													}
												} else if (result == null) {
													if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
												}
											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(updPushTokenEvent);

										/* 讀取個人樹資料 */
										QueryPersonalScoreEvent mQueryPersonalScoreEvent = new QueryPersonalScoreEvent(TreeActivity.this);
										mQueryPersonalScoreEvent.addCallback(new IEventCallback() {
											@Override
											public void result(Event event, Object result) {
												Message msg = new Message();
												msg.what = SETTEXT_FOR_TEXTVIEW;
												msg.arg1 = R.id.member_name;
												String tempString1 = PersonalBean.getInstance().getMembername();
												if (tempString1.length() > 8) {
													msg.obj = tempString1.substring(0, 8) + "...";
												} else {
													msg.obj = tempString1;
												}
												tempString1 = null;
												// msg.obj =
												// PersonalBean.getInstance().getMembername();
												mHandler.sendMessage(msg);

												Message msg2 = new Message();
												msg2.what = SETTEXT_FOR_TEXTVIEW;
												msg2.arg1 = R.id.member_totalscore;
												msg2.obj = String.valueOf(PersonalBean.getInstance().getTotalScore());
												mHandler.sendMessage(msg2);
												/* 判斷是否秀個人樹果實 */
												if (PersonalBean.getInstance().getFruitSurplus() > 0) {
													personalfruit_count = PersonalBean.getInstance().getFruitSurplus();
													Message message = mHandler.obtainMessage(SHOW_PERSONALFRUIT);
													mHandler.sendMessage(message);
												}
											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(mQueryPersonalScoreEvent);
									}

								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {
								}
							});

							/* 個人樹EVENT後加入讀取留言EVENT為SubEvent */
							QueryMemberContentEvent memberContentEvent = new QueryMemberContentEvent(TreeActivity.this);
							memberContentEvent.addCallback(new IEventCallback() {

								@Override
								public void result(Event event, Object result) {
									memberContentData.clear();
									memberContentData.addAll((Collection<? extends QueryMemberContentBean>) result);
									Message msg = mHandler.obtainMessage(MEMBERCONTENT_ADAPTER_NOTIFY_DATA);
									mHandler.sendMessage(msg);
								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {
								}
							});

							loginEvent.addSubEvent(memberContentEvent);

							KenEventManager.getInstance().execute(loginEvent);
						} else {
							Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
						}

						// ===============
					}
				});

			}
			/* 有sn登入過載入個人樹頁面 */
			else {

				// Cliff add
				((Olympic) this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL;

				initPersonalLayout();
				/* 讀取個人樹資料 */
				QueryPersonalScoreEvent mQueryPersonalScoreEvent = new QueryPersonalScoreEvent(TreeActivity.this);
				mQueryPersonalScoreEvent.addCallback(new IEventCallback() {

					@Override
					public void result(Event event, Object result) {
						String memberName;
						if (PersonalBean.getInstance().getMembername().equals("")) {
							int index = PersonalBean.getInstance().getNickname().indexOf("@");
							if (index != -1) {
								memberName = "我的個人樹";
							} else {
								String tempString1 = PersonalBean.getInstance().getNickname();
								if (tempString1.length() > 8) {
									memberName = tempString1.substring(0, 8) + "...";
								} else {
									memberName = tempString1;
								}
								tempString1 = null;
							}

						} else {
							String tempString1 = PersonalBean.getInstance().getMembername();
							if (tempString1.length() > 8) {
								memberName = tempString1.substring(0, 8) + "...";
							} else {
								memberName = tempString1;
							}
							tempString1 = null;
						}

						Message msg = new Message();
						msg.what = SETTEXT_FOR_TEXTVIEW;
						msg.arg1 = R.id.member_name;
						msg.obj = memberName;
						mHandler.sendMessage(msg);

						Message msg2 = new Message();
						msg2.what = SETTEXT_FOR_TEXTVIEW;
						msg2.arg1 = R.id.member_totalscore;
						msg2.obj = String.valueOf(PersonalBean.getInstance().getTotalScore());
						mHandler.sendMessage(msg2);
						/* 判斷是否秀個人樹果實 */
						if (PersonalBean.getInstance().getFruitSurplus() > 0) {
							personalfruit_count = PersonalBean.getInstance().getFruitSurplus();
							Message message = mHandler.obtainMessage(SHOW_PERSONALFRUIT);
							mHandler.sendMessage(message);
						}
					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				/* 個人樹EVENT後加入讀取留言EVENT為SubEvent */
				QueryMemberContentEvent memberContentEvent = new QueryMemberContentEvent(TreeActivity.this);
				memberContentEvent.addCallback(new IEventCallback() {

					@Override
					public void result(Event event, Object result) {
						memberContentData.clear();
						memberContentData.addAll((Collection<? extends QueryMemberContentBean>) result);
						Message msg = mHandler.obtainMessage(MEMBERCONTENT_ADAPTER_NOTIFY_DATA);
						mHandler.sendMessage(msg);
					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {

					}
				});

				KenEventManager.getInstance().execute(memberContentEvent);
				KenEventManager.getInstance().execute(mQueryPersonalScoreEvent);

			}
		}

	}

	// Cliff add
	public void gotoTabAR() {

		/* popraw開啟時無法點擊 */
		if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
			// cleanerInit2();
			Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "呼喚加油寶寶中…");// 秀轉轉
			mHandler.sendMessage(msg);

			GetCameraBabyEvent cameraBabyEvent = new GetCameraBabyEvent(TreeActivity.this, user_loc);
			cameraBabyEvent.addCallback(new IEventCallback() {

				@Override
				public void result(Event event, Object result) {

					/* 連線失敗 */
					if (result instanceof String && ((String) result).equals("ERROR")) {
						if (IS_DEBUG) {Log.d("ken", "網路異常");}

						Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
						mHandler.sendMessage(msg2);
						Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_MESSAGE, "網路連線異常");
						mHandler.sendMessage(msg);

					} else {
						// Cliff add
						((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.AR;
						//
						getCameraBabyData.clear();
						getCameraBabyData.addAll((Collection<? extends GetCameraBabyBean>) result);

						Olympic olympicState = (Olympic) getApplicationContext();
						olympicState.setCamerababyData(getCameraBabyData);

						GetStoreInfoEvent getStoreInfoEvent = new GetStoreInfoEvent(TreeActivity.this, user_loc);
						getStoreInfoEvent.addCallback(new IEventCallback() {

							@Override
							public void result(Event event, Object result) {
								storeInfoData.clear();
								storeInfoData.addAll((Collection<? extends GetStoreInfoBean>) result);

								Olympic olympicState = (Olympic) getApplicationContext();
								olympicState.setStoreInfoData(storeInfoData);

								Intent it = new Intent();
								it.setClass(TreeActivity.this, ARExampleActivity.class);
								startActivityForResult(it, GETBABY_RESULT);
								Message msg = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 取消秀轉轉
								mHandler.sendMessage(msg);
							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});

						KenEventManager.getInstance().execute(getStoreInfoEvent);

					}

				}

				@Override
				public void progress(Event event, int progress, String tmpPath) {
				}
			});
			KenEventManager.getInstance().execute(cameraBabyEvent);

			// startActivity(it);
		}

	}

	// Cliff Add
	public void gotoTabMember() {

		/* popraw開啟時無法點擊 */
		if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
			cleanerLayout();
			/* 讀取sn來確定是否登入過 */

			if (KenEventManager.getInstance().getCHTsn() == 0) {
				/* 沒有sn未登入過 */
				try {
					loginPage = (RelativeLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_login_pertreepage, null);
					setLayoutView(loginPage);
				} catch (Exception e) {
				}

				/* 登入背景說明頁 */
				showLoginInfo();

				// // Cliff add
				// ((Olympic)this.getApplication()).mPageIndex =
				// Olympic.PageIndex.MEMBER_LOGIN;

				/* 設定頁面title */
				TextView title = (TextView) loginPage.findViewById(R.id.login_titlekind);
				title.setText("照集簿");

				/* 返回按鈕 */
				ImageView btn_back = (ImageView) findViewById(R.id.perpage_back);
				btn_back.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						if (!loginInfoPageisOpen) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									findViewById(R.id.perpage_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

							cleanerLayout();
							setBackgroundLayout();
							loginPage = null;
							((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
						}
					}
				});
				/* 加入會員按鈕 */
				ImageView btn_addMember = (ImageView) findViewById(R.id.perpage_addmember);
				btn_addMember.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
					}
				});
				/* 忘記密碼按鈕 */
				ImageView btn_forGetpass = (ImageView) findViewById(R.id.perpage_forgetpss);
				btn_forGetpass.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
					}
				});
				/* 登入按鈕 */
				ImageView btn_Login = (ImageView) findViewById(R.id.perpage_login);
				btn_Login.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// =============
						EditText account = (EditText) findViewById(R.id.perpage_account);
						EditText password = (EditText) findViewById(R.id.perpage_password);

						if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
						if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
						/* 判斷欄位是否有未填 */
						if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
								&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									password.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

							/* 轉轉 */
							Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
							mHandler.sendMessage(msg);

							PersonalBean.getInstance().setAccount(account.getText().toString());
							PersonalBean.getInstance().setPassword(password.getText().toString());
							LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
							loginEvent.addCallback(new IEventCallback() {
								@Override
								public void result(Event event, Object result) {
									/* 取消轉轉 */
									Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
									mHandler.sendMessage(msg2);

									if (((PersonalBean) result).getChtsn() == 0 || ((PersonalBean) result).getUserType() == -1) {

										Message msg = mHandler.obtainMessage(MSG_SHOW, ((PersonalBean) result).getLoginMessage());
										mHandler.sendMessage(msg);
										if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
									} else {
										/* 儲存sn */
										KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
										/* 儲存帳號 */
										KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
										/* 儲存nickname */
										KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
										/* 儲存usertype */
										KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
										if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}
										
										/* 推播更新 */
										UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null,
												((Olympic) getApplicationContext()).getRegistrationID());
										updPushTokenEvent.addCallback(new IEventCallback() {

											@Override
											public void result(Event event, Object result) {
												if (result instanceof UpdPushTokenBean) {
													if (((UpdPushTokenBean) result).getResult() == 0000) {
														if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
														// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
													}
												} else if (result == null) {
													if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
												}

											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(updPushTokenEvent);
										/* 設定layout */
										loginPage = null;
										Message msg = new Message();
										msg.what = SET_LAYOUTVIEW;
										msg.arg1 = 4;
										mHandler.sendMessage(msg);
									}

								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {

								}
							});
							KenEventManager.getInstance().execute(loginEvent);
						} else {
							Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
						}
						// ===============

					}
				});
			} else {
				/* 載入收集冊 */
				intoMemberLayout();
			}
		}

	}

	// Cliff Add
	public void gotoTabMore() {

		/* popraw開啟時無法點擊 */
		if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
			// Cliff Add
			((Olympic) this.getApplication()).mPageIndex = Olympic.PageIndex.MORE;
			//
			cleanerLayout();
			more_Page = (RelativeLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.more_page, null);
			morepage_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.b_1_bg_02));
			more_Page.setBackgroundDrawable(morepage_bmpDrawImg);
			LinearLayout morePageBg = (LinearLayout) more_Page.findViewById(R.id.more_page_bg);
			morepageBgbitmap = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg1_06_1));
			morePageBg.setBackgroundDrawable(morepageBgbitmap);

			TextView verCodeText = (TextView) more_Page.findViewById(R.id.more_page_ver);
			verCodeText.setText("版本  "+ verCode);
			// Cliff Add
			infosView.loadUrl("about:blank");
			setLayoutView(more_Page);
			addToolbar(TreeActivity.this, 4);
			// tabOnClick(4);
		}

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		//TODO 強制定義自己軟體的對內存大小
		int CWJ_HEAP_SIZE = 6* 1024* 1024 ;
//		VMRuntime.getRuntime().setMinimumHeapSize(CWJ_HEAP_SIZE);
//		Log.e("ken", "HeapSize"+VMRuntime.getRuntime().getMinimumHeapSize());
		// Cliff add for G Sensor
		mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
		mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

		if (mAccSensor != null)
			isAccSensorSupported = true;

		Log.e("ken", "w"+Helper.getScreenWidth(this) +"h"+Helper.getScreenHeight(this)+" "+android.os.Build.MODEL);
		
		KenEventManager.getInstance().init(this);

		LayoutInflater inflater = LayoutInflater.from(this);
		layout1_a = inflater.inflate(R.layout.treeactlayout1, null);

		treeListData = new ArrayList<TreeAllBean>();// 加油樹ArrayList
		canLikeTreeListData = new ArrayList<TreeAllBean>();// 尚可加油選手ArrayList
		treeSingleListData = new ArrayList<TreeSingleBean>();// 留言ArrayList
		memberContentData = new ArrayList<QueryMemberContentBean>();// 會員留言ArrayList
		memberContentData.add(new QueryMemberContentBean(5, 5, 5, 5, "itemname", 1234567890, "itemdescription", "treename"));
	    
		quertPersonCouponData = new ArrayList<QueryPersonCouponBean>();// 會員個人優惠果實ArrayList
		quertPersonCouponDataOfKind = new ArrayList<QueryPersonCouponBean>();
		sportBabyListDataOrg = new ArrayList<SportBabyListBean>();// 原始寶寶列表ArrayList
		sportBabyListData = new ArrayList<SportBabyListBean>();// 寶寶列表ArrayList
		queryPersonBabyData = new ArrayList<QueryPersonalBabyBean>();// 會員寶寶列表ArrayList
		getCameraBabyData = new ArrayList<GetCameraBabyBean>(); // 可照集寶寶列表ArrayList
		storeInfoData = new ArrayList<GetStoreInfoBean>(); // 商家列表ArrayList
		shareBabyListData = new ArrayList<Integer>(); // 可交換的加油寶寶清單ArrayList
		memberCanShareList = new ArrayList<Integer>(); // 會員可分享寶寶清單ArrayList

		toolBar = null;
		setBackgroundLayout();

		// webview
		infosViewPanel = new RelativeLayout(TreeActivity.this);
		infosViewPanel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		infosViewPanel.setBackgroundColor(Color.WHITE);
		infosView = new WebView(TreeActivity.this);
		infosView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, (int) (Helper.getScreenHeight(TreeActivity.this) * 0.85f)));
		infosView.getSettings().setJavaScriptEnabled(true);
		infosView.getSettings().setAppCacheEnabled(true);
		infosView.getSettings().setSupportZoom(true);
		infosView.getSettings().setLoadWithOverviewMode(true);
		infosView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
		infosView.getSettings().setUseWideViewPort(true);
		infosView.getSettings().setUserAgentString("Android");
		// Cliff add
		infosView.setWebViewClient(mWebViewClient);
		infosView.setOnKeyListener(new OnKeyListener() {

			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (event.getAction() == KeyEvent.ACTION_DOWN) {
					if (keyCode == KeyEvent.KEYCODE_BACK) { // watch back key
															// event...
						// go back to Tab More...
						gotoTabMore();
						return true;
					}
				}
				return false;
			}

		});
		infosViewPanel.addView(infosView);

		// ListView
		mTreeListView = (RefreshableListView) findViewById(R.id.tree_listview);
		mTreeAllAdapter = new TreeAllAdapter(this, treeListData, mHandler);
		mTreeListView.setAdapter(mTreeAllAdapter);
		mTreeListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
		// FBConnector
		facebookConnector = new FacebookConnector(FACEBOOK_APPID, this, getApplicationContext(), FACEBOOK_PERMISSION);

		/* 定位 */
		mLocationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
		mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
		mLocationManager.getProviders(true);
		// mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
		// 0, 0, new LocationListener() {
		// @Override
		// public void onStatusChanged(String provider, int status, Bundle
		// extras) {
		// }
		// @Override
		// public void onProviderEnabled(String provider) {
		// }
		// @Override
		// public void onProviderDisabled(String provider) {
		// }
		// @Override
		// public void onLocationChanged(Location location) {
		// }
		// });
		user_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		if (user_loc == null) {
			user_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
		}

		/** tab按鈕 */
		/* 加油樹按鈕 */
		ImageView tab_tree = (ImageView) findViewById(R.id.tooltab0);
		tab_tree.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Cliff Modified...
				if (lockscreen == false) {
					lockscreen = true;
					gotoTabTree();
					/* 判斷如果選手樹資料為0筆時重LOAD */
					if (treeListData.size() < 1) {
						// 抓選手樹資料
						// Message msg1 =
						// mHandler.obtainMessage(PROGRESSDIALOD_SHOW,
						// "進入選手樹群中...");//秀轉轉
						// mHandler.sendMessage(msg1);
						// 抓伺服器時間
						SeverTimeEvent severTimeEvent = new SeverTimeEvent(TreeActivity.this);
						KenEventManager.getInstance().execute(severTimeEvent);
						// 抓選手樹資料
						GetTreeAllEvent mGetTreeAllEvent = new GetTreeAllEvent(TreeActivity.this);
						mGetTreeAllEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {

								/* 連線失敗 */
								if (result instanceof String && ((String) result).equals("ERROR")) {
									if (IS_DEBUG) {Log.d("ken", "網路異常");}
									// Message msg =
									// mHandler.obtainMessage(SHOW_ALERTDIALOG_NOINTERNET);
									// mHandler.sendMessage(msg);
									// Message msg2 =
									// mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
									// mHandler.sendMessage(msg2);
								} else {
									/* 連線正常 */
									if (((Collection<? extends TreeAllBean>) result).size() > 0) {
										treeListData.clear();
										treeListData.addAll((Collection<? extends TreeAllBean>) result);
										Message msg = mHandler.obtainMessage(TREEALL_ADAPTER_NOTIFY_DATA);
										mHandler.sendMessage(msg);
										Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
										mHandler.sendMessage(msg2);
										mTreeListView.setLoaningString(getDateTime());// 設定更新時間
									}
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});
						KenEventManager.getInstance().execute(mGetTreeAllEvent);
						// 抓寶寶列表資料
						SportBabyListEvent mSportBabyListEvent = new SportBabyListEvent(TreeActivity.this);
						mSportBabyListEvent.addCallback(new IEventCallback() {

							@Override
							public void result(Event event, Object result) {
								/* 連線正常 */
								if (((Collection<? extends SportBabyListBean>) result).size() > 0) {
									sportBabyListDataOrg.clear();
									sportBabyListDataOrg.addAll((Collection<? extends SportBabyListBean>) result);
								}
								/* 連線失敗 */
								else {
									if (IS_DEBUG) {Log.d("ken", "網路異常");}
									Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_NOINTERNET);
									mHandler.sendMessage(msg);
								}
							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});
						KenEventManager.getInstance().execute(mSportBabyListEvent);
					}

					lockscreen = false;
				}

			}
		});

		/* 個人樹按鈕 */
		ImageView tab_personal = (ImageView) findViewById(R.id.tooltab1);
		tab_personal.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Cliff Modified...
				if (lockscreen == false) {
					lockscreen = true;
					gotoTabPresonal();
					lockscreen = false;
				}
			}
		});

		/* AR抓寶寶按鈕 */
		ImageView tab_Ar = (ImageView) findViewById(R.id.tooltab2);
		tab_Ar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Cliff Modified...
				if (lockscreen == false) {
					lockscreen = true;
					gotoTabAR();
					lockscreen = false;
				}
			}
		});

		/* 收集冊按鈕 */
		ImageView tab_member = (ImageView) findViewById(R.id.tooltab3);
		tab_member.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Cliff Modified...
				if (lockscreen == false) {
					lockscreen = true;
					gotoTabMember();
					lockscreen = false;
				}
			}

		});

		/* 更多按鈕 */
		ImageView tab_more = (ImageView) findViewById(R.id.tooltab4);
		tab_more.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Cliff Modified...
				if (lockscreen == false) {
					lockscreen = true;
					gotoTabMore();
					lockscreen = false;
				}
			}
		});

		// ====================init==========
		// 抓選手樹資料
		Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "進入選手樹群中...");// 秀轉轉
		mHandler.sendMessage(msg1);
		// 抓伺服器時間
		SeverTimeEvent severTimeEvent = new SeverTimeEvent(TreeActivity.this);
		KenEventManager.getInstance().execute(severTimeEvent);
		// 抓選手樹資料
		GetTreeAllEvent mGetTreeAllEvent = new GetTreeAllEvent(this);
		mGetTreeAllEvent.addCallback(new IEventCallback() {
			@Override
			public void result(Event event, Object result) {

				/* 連線失敗 */
				if (result instanceof String && ((String) result).equals("ERROR")) {
					if (IS_DEBUG) {Log.d("ken", "網路異常");}
					Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_NOINTERNET);
					mHandler.sendMessage(msg);

				} else {
					/* 連線正常 */
					if (((Collection<? extends TreeAllBean>) result).size() > 0) {
						treeListData.clear();
						treeListData.addAll((Collection<? extends TreeAllBean>) result);
						Message msg = mHandler.obtainMessage(TREEALL_ADAPTER_NOTIFY_DATA);
						mHandler.sendMessage(msg);
						Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
						mHandler.sendMessage(msg2);
						mTreeListView.setLoaningString(getDateTime());// 設定更新時間
					}
				}

			}

			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(mGetTreeAllEvent);
		// 抓寶寶列表資料
		SportBabyListEvent mSportBabyListEvent = new SportBabyListEvent(TreeActivity.this);
		mSportBabyListEvent.addCallback(new IEventCallback() {

			@Override
			public void result(Event event, Object result) {
				/* 連線正常 */
				if (((Collection<? extends SportBabyListBean>) result).size() > 0) {

					sportBabyListDataOrg.clear();
					sportBabyListDataOrg.addAll((Collection<? extends SportBabyListBean>) result);
					Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
					mHandler.sendMessage(msg2);
					// TODO 比對lastmodify
					CheckBabyLastmodifyEvent checkBabyLastmodifyEvent = new CheckBabyLastmodifyEvent(TreeActivity.this,
							(List<SportBabyListBean>) result);
					checkBabyLastmodifyEvent.addCallback(new IEventCallback() {
						@Override
						public void result(Event event, Object result) {
							if (IS_DEBUG) {Log.d("ken", "download完成");}
						}

						@Override
						public void progress(Event event, int progress, String tmpPath) {
						}
					});
					KenEventManager.getInstance().execute(checkBabyLastmodifyEvent);
				}
				/* 連線失敗 */
				else {
					if (IS_DEBUG) {Log.d("ken", "網路異常");}
					Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_NOINTERNET);
					mHandler.sendMessage(msg);
				}
			}

			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(mSportBabyListEvent);
		// 可交換寶寶清單
		ShareBabyListEvent mShareBabyListEvent = new ShareBabyListEvent(TreeActivity.this);
		mShareBabyListEvent.addCallback(new IEventCallback() {
			@Override
			public void result(Event event, Object result) {
				shareBabyListData.clear();
				shareBabyListData.addAll((Collection<? extends Integer>) result);
			}

			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(mShareBabyListEvent);

		/** 下拉更新 */
		mTreeListView.setOnRefreshListener(new OnRefreshListener() {
			@Override
			public void onRefresh() {
				// 抓選手樹資料
				GetTreeAllEvent mGetTreeAllEvent = new GetTreeAllEvent(TreeActivity.this);
				mGetTreeAllEvent.addCallback(new IEventCallback() {
					@Override
					public void result(Event event, Object result) {
						/* 連線失敗 */
						if (result instanceof String && ((String) result).equals("ERROR")) {
							if (IS_DEBUG) {Log.d("ken", "網路異常");}
							Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_NOINTERNET);
							mHandler.sendMessage(msg);
							// Message msg2 =
							// mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
							// mHandler.sendMessage(msg2);
						} else {
							/* 連線正常 */
							if (((Collection<? extends TreeAllBean>) result).size() > 0) {
								treeListData.clear();
								treeListData.addAll((List<TreeAllBean>) result);
								Message msg = mHandler.obtainMessage(TREEALL_ADAPTER_NOTIFY_DATA);
								mHandler.sendMessage(msg);
								// Message msg2 =
								// mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
								// mHandler.sendMessage(msg2);
								mTreeListView.setLoaningString(getDateTime());// 設定更新時間
							}
						}
					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(mGetTreeAllEvent);
			}
		});
		/** 點擊進選手樹 */
		mTreeListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				int position = arg2 - 1;// 因為有加更新的haed所以position須減1
				initLayout2(position);
				QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this, treeListData.get(position)
						.getTreeId());
				mGetTreeSingleEvent.addCallback(new IEventCallback() {
					@Override
					public void result(Event event, Object result) {
						treeSingleListData.clear();
						treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
						Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
						mHandler.sendMessage(msg);

					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(mGetTreeSingleEvent);
			}
		});

		if (TreeActivity.this.getIntent() != null) {
			Bundle tBund = TreeActivity.this.getIntent().getExtras();
			if (tBund.getBoolean("pushIn")) {
				/* 推播更新 */
				UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null, ((Olympic) getApplicationContext()).getRegistrationID(),
						true);
				updPushTokenEvent.addCallback(new IEventCallback() {

					@Override
					public void result(Event event, Object result) {
						if (result instanceof UpdPushTokenBean) {
							if (((UpdPushTokenBean) result).getResult() == 0000) {
								if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
							}
						} else if (result == null) {
							if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
						}
					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(updPushTokenEvent);
			}
		}

	}

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {

			case FB_LIKE:
				try {
					String kindname = null;
					switch (canLikeTreeListData.get(spinerselect).getTreeType()) {
					case 1:
						kindname = "水上運動選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 2:
						kindname = "射箭選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 3:
						kindname = "田徑選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 4:
						kindname = "射擊選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 5:
						kindname = "桌球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 6:
						kindname = "跆拳道選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 7:
						kindname = "舉重選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 8:
						kindname = "自由車選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 9:
						kindname = "擊劍選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 10:
						kindname = "帆船選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 11:
						kindname = "羽球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 12:
						kindname = "柔道選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 13:
						kindname = "划船選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 14:
						kindname = "網球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					}
					NOfbAgain = kindname;
					requestUserInfo(kindname, null);
					kindname = null;
				} catch (Exception e) {
				}
				break;

			case FB_WALLPOST:
				try {
					String kindname = null;
					switch (canLikeTreeListData.get(spinerselect).getTreeType()) {
					case 1:
						kindname = "水上運動選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 2:
						kindname = "射箭選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 3:
						kindname = "田徑選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 4:
						kindname = "射擊選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 5:
						kindname = "桌球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 6:
						kindname = "跆拳道選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 7:
						kindname = "舉重選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 8:
						kindname = "自由車選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 9:
						kindname = "擊劍選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 10:
						kindname = "帆船選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 11:
						kindname = "羽球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 12:
						kindname = "柔道選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 13:
						kindname = "划船選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					case 14:
						kindname = "網球選手" + canLikeTreeListData.get(spinerselect).getTreeName();
						break;
					}
					NOfbAgain = kindname;
					requestUserInfo(kindname, (String) msg.obj);
					kindname = null;
				} catch (Exception e) {
				}
				break;
			case MSGUPLOAD_ERROR:
				try {
					Helper.ShowMessage(TreeActivity.this, "留言失敗", "一小時內已加油過 (已按讚)", 0, null, null, null, null);
				} catch (Exception e) {
				}
				break;

			case MSG_SHOW:
				try {
					// Helper.ShowMessage(TreeActivity.this, "", (String)
					// msg.obj, 0, null, null, null, null);
					Toast.makeText(TreeActivity.this, (String) msg.obj, Toast.LENGTH_LONG).show();
				} catch (Exception e) {
				}
				break;

			case SHOW_ALERTDIALOG_MESSAGE:
				try {
					String[] title = { "確定" };
					Helper.ShowMessage(TreeActivity.this, "", (String) msg.obj, 1, title, new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
						}
					}, null, null);

				} catch (Exception e) {
				}

				break;

			case PROGRESSDIALOD_SHOW:
				progressDialog = ProgressDialog.show(TreeActivity.this, "", (String) msg.obj, true);
				break;

			case SHOW_TOAST:
				Toast.makeText(TreeActivity.this, (String) msg.obj, Toast.LENGTH_LONG).show();
				break;

			case PROGRESSDIALOD_CANCEL:
				if (progressDialog != null) {
					progressDialog.cancel();
					progressDialog = null;
				}

				break;

			case INITLAYOUT2:

				// Cliff add
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.AR_MESSAGE;
				//
				/*有msg.arg2表示由照集進入 */
				cleanerLayout();
				if(msg.arg2 == 0){
					initLayout2(msg.arg1);
				}else{
					int position = 0;
					for (int i = 0; i < treeListData.size(); i++) {
						if (msg.arg2 == treeListData.get(i).getTreeId() ) {
							position = treeListData.indexOf(treeListData.get(i));
						}
					}
					initLayout2(position);
				}
				
				break;

			case SHOW_GIFTLAYOUT:

				final int gift_type = msg.arg1;
				if (msg.arg1 == 1) {
					// Cliff add
					((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE_CONTESTANY_GIFT0;
					//
				} else if (msg.arg1 == 2) {
					// Cliff add
					((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL_GIFT;
					//
				} else if (msg.arg1 == 3) {
					// Cliff add
					((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_GIFT;
					//
				}

				if (getGiftPage != null) {
					getGiftPage.setVisibility(View.GONE);
					getGiftPage.removeAllViews();
					getGiftPage = null;
				}

				LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
				getGiftPage = (RelativeLayout) inflater.inflate(R.layout.by_getgift, null);
				addContentView(getGiftPage, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
				giftMsgPopisOpen = true;

				if (msg.obj instanceof CHTContentUploadBean) {
					final CHTContentUploadBean bean = (CHTContentUploadBean) msg.obj;
					// getGiftType.setText(String.valueOf(bean.getGiftName()));
					TextView getGiftMsg = (TextView) getGiftPage.findViewById(R.id.getgift_msg);
					String giftName = bean.getGiftName();
					try {
						int idx = Helper.getFirstAlphaIndex(giftName);
						giftName = Helper.insertString(giftName, idx, "\n");
					} catch (Exception e) {
						giftName = bean.getGiftName();
					}
					getGiftMsg.setText(giftName);
					/* 禮物文案 */
					Message msg2 = new Message();
					msg2.what = SETTEXT_FOR_TEXTVIEW;
					msg2.arg1 = R.id.getgift_bottomtext;
					if (bean.getGiftId() == 1) {
						msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 2) {
						msg2.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 4) {
						msg2.obj = "※請務必保留金牌密碼，以作後續領獎證明使用！";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 3) {
						msg2.obj = "※系統統一於次月五號給予歡樂點至得獎者中華電信會員帳號中";
						mHandler.sendMessage(msg);
					}
					ImageView getGiftUrl = (ImageView) findViewById(R.id.getgift_url);
					getGiftUrl.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							String sn = String.valueOf(KenEventManager.getInstance().getCHTsn());
							String giftid = String.valueOf(bean.getGiftId());
							String check = KenEventManager.getInstance().genCheckCode(sn + "1");

							if (bean.getGiftId() == 1) {
								String url = "http://sports.hinet.net/2012olygame/print/award/print_award.php?";
								// Log.d("ken", "Uri" + url+"sn="+ sn +
								// "&type=1&gift_id=" + giftid + "&check="
								// +check);
								Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(url + "sn=" + sn + "&type=1&gift_id=" + giftid
										+ "&check=" + check));
								startActivity(it);
							} else if (bean.getGiftId() == 2) {
								Intent it4 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
								startActivity(it4);
							} else if (bean.getGiftId() == 3) {
								Intent it3 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cheerspoint.unisurf.tw/"));
								startActivity(it3);
							} else if (bean.getGiftId() == 4) {
								String url2 = "http://sports.hinet.net/2012olygame/print/gold/print_gold_sn.php?";
								Intent it2 = new Intent(Intent.ACTION_VIEW, Uri.parse(url2 + "sn=" + sn + "&type=1&gift_id=" + giftid
										+ "&check=" + check));
								startActivity(it2);
							} else {
								Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
								startActivity(it);
							}

						}
					});

				} else if (msg.obj instanceof MemberSelfGetFruitBean) {
					final MemberSelfGetFruitBean bean = (MemberSelfGetFruitBean) msg.obj;
					// getGiftType.setText(String.valueOf(bean.getGiftName()));
					TextView getGiftMsg = (TextView) getGiftPage.findViewById(R.id.getgift_msg);
					String giftName = bean.getGiftName();
					try {
						int idx = Helper.getFirstAlphaIndex(giftName);
						giftName = Helper.insertString(giftName, idx, "\n");
					} catch (Exception e) {
						giftName = bean.getGiftName();
					}
					getGiftMsg.setText(giftName);
					/* 禮物文案 */
					Message msg2 = new Message();
					msg2.what = SETTEXT_FOR_TEXTVIEW;
					msg2.arg1 = R.id.getgift_bottomtext;
					if (bean.getGiftId() == 1) {
						msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 2) {
						msg2.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 4) {
						msg2.obj = "※請務必保留金牌密碼，以作後續領獎證明使用！";
						mHandler.sendMessage(msg);
					} else if (bean.getGiftId() == 3) {
						msg2.obj = "※系統統一於次月五號給予歡樂點至得獎者中華電信會員帳號中";
						mHandler.sendMessage(msg);
					}

					ImageView getGiftUrl = (ImageView) getGiftPage.findViewById(R.id.getgift_url);
					getGiftUrl.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							String sn = String.valueOf(KenEventManager.getInstance().getCHTsn());
							String giftid = String.valueOf(bean.getGiftId());
							String check = KenEventManager.getInstance().genCheckCode(sn + "1");

							if (bean.getGiftId() == 1) {
								String url = "http://sports.hinet.net/2012olygame/print/award/print_award.php?";
								Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(url + "sn=" + sn + "&type=1&gift_id=" + giftid
										+ "&check=" + check));
								startActivity(it);
							} else if (bean.getGiftId() == 2) {
								Intent it4 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
								startActivity(it4);
							} else if (bean.getGiftId() == 3) {
								Intent it3 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cheerspoint.unisurf.tw/"));
								startActivity(it3);
							} else if (bean.getGiftId() == 4) {
								String url2 = "http://sports.hinet.net/2012olygame/print/gold/print_gold_sn.php?";
								Intent it2 = new Intent(Intent.ACTION_VIEW, Uri.parse(url2 + "sn=" + sn + "&type=1&gift_id=" + giftid
										+ "&check=" + check));
								startActivity(it2);
							} else {
								Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
								startActivity(it);
							}

						}
					});

				}

				ImageView cancel = (ImageView) getGiftPage.findViewById(R.id.getgift_cencel);
				cancel.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						if (getGiftPage != null) {
							getGiftPage.setVisibility(View.GONE);
							getGiftPage.removeAllViews();
							getGiftPage = null;
							giftMsgPopisOpen = false;
						}
						// Cliff add
						if (gift_type == 1) { // go back to...
							((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE_CONTESTANY;
						} else if (gift_type == 2) {
							((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL;
						} else if (gift_type == 3) {
							((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;
						}
					}
				});
				break;

			case TREEALL_ADAPTER_NOTIFY_DATA:
				try {
					// LinearLayout linearLayout = (LinearLayout)
					// layout1_a.findViewById(R.id.fullscreen_loading_indicator);
					// linearLayout.setVisibility(View.GONE);
					mTreeListView.completeRefreshing();
					mTreeAllAdapter.notifyDataSetChanged();
					// mTreeListView.setVisibility(View.VISIBLE);
				} catch (Exception e) {
				}
				break;

			case TREESINGLE_ADAPTER_NOTIFY_DATA:
				try {
					mSingleTreeListView.completeRefreshing();
					mMemberTreeAdapter.notifyDataSetChanged();
					mSingleTreeListView.setLoaningString(getDateTime());// 設定更新時間
					/* 取消轉轉 */
					ViewFlipper flipper = (ViewFlipper) findViewById(R.id.layout2_flipper);
					flipper.setDisplayedChild(0);
				} catch (Exception e) {
				}
				break;

			case MEMBERCONTENT_ADAPTER_NOTIFY_DATA:
				try {
					mQueryMemberContentAdapter.notifyDataSetChanged();
					/* 取消轉轉 */
					ViewFlipper flipper = (ViewFlipper) findViewById(R.id.personal_layout_flipper);
					flipper.setDisplayedChild(0);
				} catch (Exception e) {
				}
				break;

			case PERSONCOUPON_ADAPTER_NOTIFY_DATA:
				try {
					member_Listview.setDisplayedChild(msg.arg1);
					if (msg.arg1 == 0) {
						mQueryPersonCouponAdapter.notifyDataSetChanged();
					}
					/* 取消轉轉 */

				} catch (Exception e) {
				}
				break;

			case BABYLIST_ADAPTER_NOTIFY_DATA:
				try {
					mBabyListAdapter.notifyDataSetChanged();
				} catch (Exception e) {
				}
				break;

			case SETTEXT_FOR_TEXTVIEW:
				try {
					TextView text_view;
					text_view = (TextView) findViewById(msg.arg1);
					text_view.setText((String) msg.obj);
					// text_view.setTextSize(20);

				} catch (Exception e) {
				}
				break;
			case SHOW_PERSONALFRUIT:
				try {
					ImageView fruit = (ImageView) findViewById(R.id.personal_fruit);
					fruit.setVisibility(View.VISIBLE);
					AnimationDrawable anidraw0 = (AnimationDrawable) fruit.getDrawable();
					fruit.post(anidraw0);
				} catch (Exception e) {
				}
				break;
			case HIDE_PERSONALFRUIT:
				try {
					ImageView fruit = (ImageView) findViewById(R.id.personal_fruit);
					fruit.setVisibility(View.GONE);
				} catch (Exception e) {
				}
				break;
			case SET_LAYOUTVIEW:
				switch (msg.arg1) {
				case 1:

					// if (personal_MainLayout == null) {
					// personal_MainLayout =
					// LayoutInflater.from(TreeActivity.this).inflate(R.layout.personal_layout,
					// null);
					// }
					// setLayoutView(personal_MainLayout);
					// addToolbar(TreeActivity.this, 1);
					initPersonalLayout();
					break;

				case 2:
					setLayoutView(msgadd);
					break;

				case 4:
					intoMemberLayout();
					break;
				case 5:
					gotoTabMore();
					break;
				case 9:
					initMsgAddPage((String) msg.obj);
					break;
				}
				break;
				
			case INTO_SHAREBABYPAGE2:
				intoShareBabyPage2((RelativeLayout) msg.obj);
				break;

			case SHOW_ALERTDIALOG_NOINTERNET:
//				String[] title = { "設定", "離開" };
//				Helper.ShowMessage(TreeActivity.this, "網路連線失敗", "請確認網路連線是否正常", 2, title, new DialogInterface.OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						// TODO 網路連線失敗設定
//						mTreeListView.completeRefreshing();
//						startActivity(new Intent(Settings.ACTION_SETTINGS));
//					}
//				}, null, new DialogInterface.OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						android.os.Process.killProcess(android.os.Process.myPid());
//					}
//				});
				break;
				
			case SHOW_ALERTDIALOG_GETBABY:
				String[] title3 = { "查看", "好" };
				Helper.ShowMessage(TreeActivity.this, "接收成功", "請到照集簿的加油寶寶中查看", 2, title3, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						cleanerLayout();
						intoMemberLayout();
					}
				}, null, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						initMemberLayout(2);
					}
				});
				break;

			case SHOW_ALERTDIALOG_LOGINERROR:
				String[] title2 = { "確定" };
				Helper.ShowMessage(TreeActivity.this, "登入失敗", "無法登入軟體!請確認帳號或密碼是否錯誤，或網路連線是否正常", 1, title2,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
							}
						}, null, null);
				break;

			case SHOW_ALERTDIALOG_MSGADDBACK:

				TextView textView = new TextView(TreeActivity.this);
				textView.setGravity(Gravity.CENTER);
				textView.setText("未完成加油灌溉\n即無法為您儲存加油寶寶\n確定要離開");
				AlertDialog.Builder MyAlertDialog = new AlertDialog.Builder(TreeActivity.this);
				MyAlertDialog.setView(textView);
				MyAlertDialog.setPositiveButton("確定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						cleanerLayout();
						Intent it = new Intent();
						it.setClass(TreeActivity.this, ARExampleActivity.class);
						startActivityForResult(it, GETBABY_RESULT);
						setBackgroundLayout();
					}
				});
				MyAlertDialog.setNegativeButton("我要留言", null);
				MyAlertDialog.show();
				break;

			case ACCELEROMETER_DATA_GOT:
				break;
			}
			super.handleMessage(msg);
		}
	};

	@Override
	public void onBackPressed() {
		if (giftMsgPopisOpen == true || personalMsgPopisOpen == true || sportsmanMsgPopisOpen == true || loginInfoPageisOpen == true) {
			giftMsgPopisOpen = false;
			personalMsgPopisOpen = false;
			sportsmanMsgPopisOpen = false;
			loginInfoPageisOpen = false;
			if (treeSinglMsgPop != null) {
				treeSinglMsgPop.setVisibility(View.GONE);
				treeSinglMsgPop.removeAllViews();
				treeSinglMsgPop = null;
			}
			if (loginInfoPage != null) {
				loginInfoPage.setVisibility(View.GONE);
				loginInfoPage.removeAllViews();
				loginInfoPage = null;
				if (loginInfoBgbitmap != null && !loginInfoBgbitmap.isRecycled()) {
					loginInfoBgbitmap.recycle();
					loginInfoBgbitmap = null;
				}
				// Cliff add
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL_LOGIN;
			}

		} else {
			if (layout1_b != null) {
				cleanerLayout();
				gotoTabTree();
			} else if (setting != null) {
				cleanerLayout();
				gotoTabMore();
			} else if (member_Listview != null || member_WebView != null || bySharebabyPage!= null || bySharebabyStep1Page!= null || bySharebabyStep2Page!= null || byGetbabyPage!= null) {
				cleanerLayout();
				intoMemberLayout();
			} else if (personal_MainLayout != null || member_MainLayout != null || more_Page != null) {
				cleanerLayout();
				gotoTabTree();
			} else if (msgadd != null) {
				// cleanerLayout();
				Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_MSGADDBACK);
				mHandler.sendMessage(msg);
			} else {

				String[] title = { "是", "否" };
				Helper.ShowMessage(TreeActivity.this, "", "是否離開加油照集令？", 2, title, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						TreeActivity.this.finish();
						layout1_a = null;
						layout1_b = null;
						toolBar = null;
						android.os.Process.killProcess(android.os.Process.myPid());
						// super.onBackPressed();
					}
				}, null, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
					}
				});
			}
		}

	}

	private void tabOnClick(int index) {
		List<ImageView> tabs = new ArrayList<ImageView>();
		for (int i = 0; i < 5; i++) {
			ImageView temp = (ImageView) findViewById(R.id.tooltab0 + i);
			tabs.add(temp);
		}

		// 設定選取icon
		switch (index) {
		case 0:
			tabs.get(0).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b01_b_0));
			tabs.get(1).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b02_a_0));
			tabs.get(3).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b04_a_0));
			tabs.get(4).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b05_a_0));
			break;
		case 1:
			tabs.get(1).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b02_b_0));
			tabs.get(0).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b01_a_0));
			tabs.get(3).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b04_a_0));
			tabs.get(4).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b05_a_0));
			break;
		case 2:
			break;
		case 3:
			tabs.get(3).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b04_b_0));
			tabs.get(1).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b02_a_0));
			tabs.get(0).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b01_a_0));
			tabs.get(4).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b05_a_0));
			break;
		case 4:
			tabs.get(4).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b05_b_0));
			tabs.get(3).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b04_a_0));
			tabs.get(1).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b02_a_0));
			tabs.get(0).setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.tool_b01_a_0));
			break;
		}

	}

	public void addToolbar(Activity activity, int index) {
		if (toolBar == null) {
			LayoutInflater inflater = LayoutInflater.from(activity);
			toolBar = (RelativeLayout) inflater.inflate(R.layout.toolbar, null);
		}
		activity.addContentView(toolBar, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		tabOnClick(index);
	}

	private void setLayoutView(View layout) {
		TreeActivity.this.setContentView(layout);
	}

	private void initMemberLayout(int index) {
		final RelativeLayout member_Inside = (RelativeLayout) findViewById(R.id.member_inside);
		member_Inside.removeAllViews();
		switch (index) {
		case 1:
			// Cliff add
			((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE0;
			//
			sportBabyListData.clear();
			for (int i = 0; i < sportBabyListDataOrg.size(); i++) {
				try {
					sportBabyListData.add((SportBabyListBean) sportBabyListDataOrg.get(i).clone());
				} catch (CloneNotSupportedException e) {
					e.printStackTrace();
				}
			}
			
			member_BabyList = null;
			if (member_BabyList == null) {
				member_BabyList = (ListView) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_babylist, null);
				mBabyListAdapter = new SportBabyListAdapter(TreeActivity.this, sportBabyListData, mHandler);
				member_BabyList.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
				member_BabyList.setAdapter(mBabyListAdapter);
			}

			member_Inside.addView(member_BabyList);
			ImageView tab1_1 = (ImageView) findViewById(R.id.btn_babylist);
			ImageView tab1_2 = (ImageView) findViewById(R.id.btn_listview);
			ImageView tab1_3 = (ImageView) findViewById(R.id.btn_webview);
			tab1_1.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b01_b_04));
			tab1_2.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b02_a_04));
			tab1_3.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b03_a_04));
			break;
		case 2:

			// Cliff add
			((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;
			//
//			====
//			 member_Listview = null;
//			 if (member_Listview == null) {
//			 member_Listview = (ViewFlipper)
//			 LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
//			 null);
//			 member_Listview.setDisplayedChild(1);
//			 mQueryPersonCouponAdapter = new
//			 QueryPersonCouponAdapter(TreeActivity.this,
//			 quertPersonCouponData, mHandler);
//			 mPersonCouponListView = (ListView)
//			 member_Listview.findViewById(R.id.coupon_listview);
//			 mPersonCouponListView.setAdapter(mQueryPersonCouponAdapter);
//			 mPersonCouponListView.setDivider(new
//			 ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
//			 /*Show優惠果實*/
//			 mPersonCouponListView.setOnItemClickListener(new
//			 OnItemClickListener() {
//			 @Override
//			 public void onItemClick(AdapterView<?> arg0, View arg1, final int
//			 arg2, long arg3) {
//			 /*flag 擋重複優惠果實*/
//			 if (giftMsgPopisOpen == false) {
//			 if (getGiftPage != null) {
//			 getGiftPage.setVisibility(View.GONE);
//			 getGiftPage.removeAllViews();
//			 getGiftPage = null;
//			 }
//			
//			 LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
//			 getGiftPage = (RelativeLayout)
//			 inflater.inflate(R.layout.by_getgift, null);
//			
//			 TextView getGiftMsg = (TextView)
//			 getGiftPage.findViewById(R.id.getgift_msg);
//			
//			 // getGiftType.setText(String.valueOf(bean.getGiftName()));
//			 String giftName = quertPersonCouponData.get(arg2).getGiftName();
//			 int idx = Helper.getFirstAlphaIndex(giftName);
//			 giftName = Helper.insertString(giftName, idx, "\n");
//			 getGiftMsg.setText(giftName);
//			 addContentView(getGiftPage,new
//			 LayoutParams(LayoutParams.FILL_PARENT,
//			 LayoutParams.FILL_PARENT));
//			 giftMsgPopisOpen = true;
//			 //
//			 ((Olympic)TreeActivity.this.getApplication()).mPageIndex =
//			 Olympic.PageIndex.MEMBER_GIFT;
//			 Message msg = new Message();
//			 msg.what = SETTEXT_FOR_TEXTVIEW;
//			 msg.arg1 = R.id.getgift_bottomtext;
//			 if (quertPersonCouponData.get(arg2).getGiftCode() == 1) {
//			 msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
//			 mHandler.sendMessage(msg);
//			 }else if (quertPersonCouponData.get(arg2).getGiftCode() == 2) {
//			 msg.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
//			 mHandler.sendMessage(msg);
//			 }else if (quertPersonCouponData.get(arg2).getGiftCode() == 3) {
//			 }else if (quertPersonCouponData.get(arg2).getGiftCode() == 4) {
//			 msg.obj ="※請務必保留金牌密碼，以作後續領獎證明使用！";
//			 mHandler.sendMessage(msg);
//			 }
//			 /*關閉按鈕*/
//			 ImageView cancel = (ImageView)
//			 getGiftPage.findViewById(R.id.getgift_cencel);
//			 cancel.setOnClickListener(new OnClickListener() {
//			 @Override
//			 public void onClick(View v) {
//			 if (getGiftPage != null) {
//			 getGiftPage.setVisibility(View.GONE);
//			 getGiftPage.removeAllViews();
//			 getGiftPage = null;
//			 giftMsgPopisOpen = false;
//			 //
//			 ((Olympic)TreeActivity.this.getApplication()).mPageIndex =
//			 Olympic.PageIndex.MEMBER_PAGE1;
//			 }
//			 }
//			 });
//			 /*優惠果相關資訊*/
//			 toOpenGiftUrl(arg2);
//			 }
//			
//			 }
//			 });
//			 }
//			 member_Inside.addView(member_Listview);
//			====
			
			// TODO 出版用
			// ==========================================出版用
			QueryPersonalBabyEvent mQueryPersonalBabyEvent = new QueryPersonalBabyEvent(TreeActivity.this);
			mQueryPersonalBabyEvent.addCallback(new IEventCallback() {
				@Override
				public void result(Event event, Object result) {
					queryPersonBabyData.clear();
					queryPersonBabyData.addAll((Collection<? extends QueryPersonalBabyBean>) result);
					/*傭有可分享寶寶列表*/
					memberCanShareList.clear();
					for (int i = 0; i < queryPersonBabyData.size(); i++) {
						for (int j = 0; j < shareBabyListData.size(); j++) {
							if (queryPersonBabyData.get(i).getBabyId() == shareBabyListData.get(j) && queryPersonBabyData.get(i).getBabyNum() > 0) {
								memberCanShareList.add(queryPersonBabyData.get(i).getBabyId());
							}
						}
					}
				}
				@Override
				public void progress(Event event, int progress, String tmpPath) {
				}
			});
			KenEventManager.getInstance().execute(mQueryPersonalBabyEvent);
			intoShareBabyPage(member_Inside);
			// ==========================================出版用
			ImageView tab2_1 = (ImageView) findViewById(R.id.btn_babylist);
			ImageView tab2_2 = (ImageView) findViewById(R.id.btn_listview);
			ImageView tab2_3 = (ImageView) findViewById(R.id.btn_webview);
			tab2_1.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b01_a_04));
			tab2_2.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b02_b_04));
			tab2_3.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b03_a_04));
			break;
		case 3:

			// Cliff add
			((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE2;
			//
			// TODO 出版用
			// ===========================包版================
			memberFruitPage = (RelativeLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_fruit_page, null);
			member_Inside.addView(memberFruitPage);

			if (quertPersonCouponData.size() == 0) {
				ImageView memberfruitPage1 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_1);
				ImageView memberfruitPage2 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_2);
				ImageView memberfruitPage3 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_3);
				memberfruitPage1.setImageDrawable(null);
				memberfruitPage2.setVisibility(View.GONE);
				memberfruitPage3.setVisibility(View.GONE);

				TextView memberfruitpagetext1 = (TextView) memberFruitPage.findViewById(R.id.member_fruitpage_text1);
				TextView memberfruitpagetext2 = (TextView) memberFruitPage.findViewById(R.id.member_fruitpage_text2);
				TextView memberfruitpagetext3 = (TextView) memberFruitPage.findViewById(R.id.member_fruitpage_text3);
				TextView memberfruitpagetext4 = (TextView) memberFruitPage.findViewById(R.id.member_fruitpage_text4);
				memberfruitpagetext1.setPadding(0, 0, 0, 0);
				memberfruitpagetext1.setGravity(Gravity.CENTER);
				memberfruitpagetext1.setText("您尚未收集到優惠果實");
				memberfruitpagetext1.setTextSize(20);
				memberfruitpagetext1.setTextColor(0xff6666ff);
				memberfruitpagetext2.setText("優惠好禮介紹");
				memberfruitpagetext3.setVisibility(View.GONE);
				memberfruitpagetext4.setVisibility(View.GONE);
			}

			/* 優惠好禮介紹 */
			ImageView memberfruitPageWeb = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_web);
			memberfruitPageWeb.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					member_WebView = LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_webview, null);
					((WebView) member_WebView).getSettings().setJavaScriptEnabled(true);
					((WebView) member_WebView).getSettings().setBuiltInZoomControls(true);
					((WebView) member_WebView).loadUrl("http://210.71.254.223/olympic/notices");
					((WebView) member_WebView).setWebViewClient(new WebViewClient());
					member_Inside.addView(member_WebView);
				}
			});

			/* 中華電信好禮 */
			ImageView memberfruitPage1 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_1);
			memberfruitPage1.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					member_Inside.removeAllViews();
					quertPersonCouponDataOfKind.clear();
					for (int i = 0; i < quertPersonCouponData.size(); i++) {
						if (quertPersonCouponData.get(i).getGiftCode() == 1 || quertPersonCouponData.get(i).getGiftCode() == 6) {
							quertPersonCouponDataOfKind.add(quertPersonCouponData.get(i));
						}
					}

					if (quertPersonCouponDataOfKind.size() == 0) {
						member_Listview = null;
						member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
								null);
						member_Inside.addView(member_Listview);
						/* 沒有優惠果實 */
						Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 2, -1);
						mHandler.sendMessage(msg);
					} else {
						member_Listview = null;
						if (member_Listview == null) {
							member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
									null);
							// member_Listview.setDisplayedChild(1);
							mQueryPersonCouponAdapter = new QueryPersonCouponAdapter(TreeActivity.this, quertPersonCouponDataOfKind,
									mHandler);
							mPersonCouponListView = (ListView) member_Listview.findViewById(R.id.coupon_listview);
							mPersonCouponListView.setAdapter(mQueryPersonCouponAdapter);
							mPersonCouponListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
							/* Show優惠果實 */
							mPersonCouponListView.setOnItemClickListener(new OnItemClickListener() {
								@Override
								public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
									/* flag 擋重複優惠果實 */
									if (giftMsgPopisOpen == false) {
										if (getGiftPage != null) {
											getGiftPage.setVisibility(View.GONE);
											getGiftPage.removeAllViews();
											getGiftPage = null;
										}

										LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
										getGiftPage = (RelativeLayout) inflater.inflate(R.layout.by_getgift, null);
										TextView getGiftMsg = (TextView) getGiftPage.findViewById(R.id.getgift_msg);
										// getGiftType.setText(String.valueOf(bean.getGiftName()));
										String giftName = quertPersonCouponDataOfKind.get(arg2).getGiftName();
										int idx = Helper.getFirstAlphaIndex(giftName);
										giftName = Helper.insertString(giftName, idx, "\n");
										getGiftMsg.setText(giftName);
										addContentView(getGiftPage, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
										giftMsgPopisOpen = true;
										//
										((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_GIFT;
										Message msg = new Message();
										msg.what = SETTEXT_FOR_TEXTVIEW;
										msg.arg1 = R.id.getgift_bottomtext;
										if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 1) {
											msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 2) {
											msg.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 3) {
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 4) {
											msg.obj = "※請務必保留金牌密碼，以作後續領獎證明使用！";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 6) {
											msg.obj = "※消費時須顯示此優惠券";
											mHandler.sendMessage(msg);
											Message message = mHandler.obtainMessage(SETTEXT_FOR_TEXTVIEW, R.id.getgift_msg2, 0, "");
											mHandler.sendMessage(message);
										}
										
										/* 關閉按鈕 */
										ImageView cancel = (ImageView) getGiftPage.findViewById(R.id.getgift_cencel);
										cancel.setOnClickListener(new OnClickListener() {
											@Override
											public void onClick(View v) {
												if (getGiftPage != null) {
													getGiftPage.setVisibility(View.GONE);
													getGiftPage.removeAllViews();
													getGiftPage = null;
													giftMsgPopisOpen = false;
													//
													((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;
												}
											}
										});
										/* 優惠果相關資訊 */
										toOpenGiftUrl(arg2);
									}

								}
							});
						}
						member_Inside.addView(member_Listview);
					}

				}
			});

			/* 歡樂點 */
			ImageView memberfruitPage2 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_2);
			memberfruitPage2.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					member_Inside.removeAllViews();
					quertPersonCouponDataOfKind.clear();
					for (int i = 0; i < quertPersonCouponData.size(); i++) {
						if (quertPersonCouponData.get(i).getGiftCode() == 3) {
							quertPersonCouponDataOfKind.add(quertPersonCouponData.get(i));
						}
					}

					if (quertPersonCouponDataOfKind.size() == 0) {
						member_Listview = null;
						member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
								null);
						member_Inside.addView(member_Listview);
						/* 沒有優惠果實 */
						Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 2, -1);
						mHandler.sendMessage(msg);
					} else {
						member_Listview = null;
						if (member_Listview == null) {
							member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
									null);
							// member_Listview.setDisplayedChild(1);
							mQueryPersonCouponAdapter = new QueryPersonCouponAdapter(TreeActivity.this, quertPersonCouponDataOfKind,
									mHandler);
							mPersonCouponListView = (ListView) member_Listview.findViewById(R.id.coupon_listview);
							mPersonCouponListView.setAdapter(mQueryPersonCouponAdapter);
							mPersonCouponListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
							/* Show優惠果實 */
							mPersonCouponListView.setOnItemClickListener(new OnItemClickListener() {
								@Override
								public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
									/* flag 擋重複優惠果實 */
									if (giftMsgPopisOpen == false) {
										if (getGiftPage != null) {
											getGiftPage.setVisibility(View.GONE);
											getGiftPage.removeAllViews();
											getGiftPage = null;
										}

										LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
										getGiftPage = (RelativeLayout) inflater.inflate(R.layout.by_getgift, null);
										TextView getGiftMsg = (TextView) getGiftPage.findViewById(R.id.getgift_msg);
										// getGiftType.setText(String.valueOf(bean.getGiftName()));
										String giftName = quertPersonCouponDataOfKind.get(arg2).getGiftName();
										int idx = Helper.getFirstAlphaIndex(giftName);
										giftName = Helper.insertString(giftName, idx, "\n");
										getGiftMsg.setText(giftName);
										addContentView(getGiftPage, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
										giftMsgPopisOpen = true;
										//
										((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_GIFT;
										Message msg = new Message();
										msg.what = SETTEXT_FOR_TEXTVIEW;
										msg.arg1 = R.id.getgift_bottomtext;
										if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 1) {
											msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 2) {
											msg.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 3) {
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 4) {
											msg.obj = "※請務必保留金牌密碼，以作後續領獎證明使用！";
											mHandler.sendMessage(msg);
										}
										/* 關閉按鈕 */
										ImageView cancel = (ImageView) getGiftPage.findViewById(R.id.getgift_cencel);
										cancel.setOnClickListener(new OnClickListener() {
											@Override
											public void onClick(View v) {
												if (getGiftPage != null) {
													getGiftPage.setVisibility(View.GONE);
													getGiftPage.removeAllViews();
													getGiftPage = null;
													giftMsgPopisOpen = false;
													//
													((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;
												}
											}
										});
										/* 優惠果相關資訊 */
										toOpenGiftUrl(arg2);
									}

								}
							});
						}
						member_Inside.addView(member_Listview);
					}

				}
			});

			/* 抽獎序號 */
			ImageView memberfruitPage3 = (ImageView) memberFruitPage.findViewById(R.id.member_fruitpage_3);
			memberfruitPage3.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					member_Inside.removeAllViews();
					quertPersonCouponDataOfKind.clear();
					for (int i = 0; i < quertPersonCouponData.size(); i++) {
						if (quertPersonCouponData.get(i).getGiftCode() == 4 || quertPersonCouponData.get(i).getGiftCode() == 2) {
							quertPersonCouponDataOfKind.add(quertPersonCouponData.get(i));
						}
					}

					if (quertPersonCouponDataOfKind.size() == 0) {
						member_Listview = null;
						member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
								null);
						member_Inside.addView(member_Listview);
						/* 沒有優惠果實 */
						Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 2, -1);
						mHandler.sendMessage(msg);
					} else {
						member_Listview = null;
						if (member_Listview == null) {
							member_Listview = (ViewFlipper) LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_coupon_listview,
									null);
							// member_Listview.setDisplayedChild(1);
							mQueryPersonCouponAdapter = new QueryPersonCouponAdapter(TreeActivity.this, quertPersonCouponDataOfKind,
									mHandler);
							mPersonCouponListView = (ListView) member_Listview.findViewById(R.id.coupon_listview);
							mPersonCouponListView.setAdapter(mQueryPersonCouponAdapter);
							mPersonCouponListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
							/* Show優惠果實 */
							mPersonCouponListView.setOnItemClickListener(new OnItemClickListener() {
								@Override
								public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
									/* flag 擋重複優惠果實 */
									if (giftMsgPopisOpen == false) {
										if (getGiftPage != null) {
											getGiftPage.setVisibility(View.GONE);
											getGiftPage.removeAllViews();
											getGiftPage = null;
										}

										LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
										getGiftPage = (RelativeLayout) inflater.inflate(R.layout.by_getgift, null);
										TextView getGiftMsg = (TextView) getGiftPage.findViewById(R.id.getgift_msg);
										// getGiftType.setText(String.valueOf(bean.getGiftName()));
										String giftName = quertPersonCouponDataOfKind.get(arg2).getGiftName();
										int idx = Helper.getFirstAlphaIndex(giftName);
										giftName = Helper.insertString(giftName, idx, "\n");
										getGiftMsg.setText(giftName);
										addContentView(getGiftPage, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
										giftMsgPopisOpen = true;
										//
										((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_GIFT;
										Message msg = new Message();
										msg.what = SETTEXT_FOR_TEXTVIEW;
										msg.arg1 = R.id.getgift_bottomtext;
										if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 1) {
											msg.obj = "※憑得獎序號即可至中華電信各營運處申辦";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 2) {
											msg.obj = "※活動結束後將抽出幸運得獎兒，祝你再添一喜";
											mHandler.sendMessage(msg);
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 3) {
										} else if (quertPersonCouponDataOfKind.get(arg2).getGiftCode() == 4) {
											msg.obj = "※請務必保留金牌密碼，以作後續領獎證明使用！";
											mHandler.sendMessage(msg);
										}
										/* 關閉按鈕 */
										ImageView cancel = (ImageView) getGiftPage.findViewById(R.id.getgift_cencel);
										cancel.setOnClickListener(new OnClickListener() {
											@Override
											public void onClick(View v) {
												if (getGiftPage != null) {
													getGiftPage.setVisibility(View.GONE);
													getGiftPage.removeAllViews();
													getGiftPage = null;
													giftMsgPopisOpen = false;
													//
													((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;
												}
											}
										});
										/* 優惠果相關資訊 */
										toOpenGiftUrl(arg2);
									}

								}
							});
						}
						member_Inside.addView(member_Listview);
					}

				}
			});
			// ========================================包版====
			//=====
//			 member_WebView = LayoutInflater.from(TreeActivity.this).inflate(R.layout.member_webview, null);
//			 ((WebView)member_WebView).getSettings().setJavaScriptEnabled(true);
//			 ((WebView)member_WebView).getSettings().setBuiltInZoomControls(true);
//			 // ((WebView)member_WebView).setInitialScale(50);
//			 ((WebView)member_WebView).getSettings().setDefaultZoom(ZoomDensity.CLOSE);
//			 ((WebView)member_WebView).loadUrl("http://210.71.254.223/olympic/notices");
//			 ((WebView)member_WebView).setWebViewClient(new WebViewClient());
//			 member_Inside.addView(member_WebView);
			//======
			ImageView tab3_1 = (ImageView) findViewById(R.id.btn_babylist);
			ImageView tab3_2 = (ImageView) findViewById(R.id.btn_listview);
			ImageView tab3_3 = (ImageView) findViewById(R.id.btn_webview);
			tab3_1.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b01_a_04));
			tab3_2.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b02_a_04));
			tab3_3.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.b03_b_04));
			break;
		}

	}

	private void intoShareBabyPage(final RelativeLayout member_Inside) {
		shareBabyCount = 0;
		/*傭有可分享寶寶列表*/
		memberCanShareList.clear();
		for (int i = 0; i < queryPersonBabyData.size(); i++) {
			for (int j = 0; j < shareBabyListData.size(); j++) {
				if (queryPersonBabyData.get(i).getBabyId() == shareBabyListData.get(j) && queryPersonBabyData.get(i).getBabyNum() > 0) {
					memberCanShareList.add(queryPersonBabyData.get(i).getBabyId());
				}
			}
		}
		member_Inside.removeAllViews();
		bySharebabyPage = null;
		if (bySharebabyPage == null) {
			bySharebabyPage = (LinearLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_sharebaby_page, null);
			/*發送寶寶頁*/
			ImageView intosharebaby = (ImageView) bySharebabyPage.findViewById(R.id.into_sharebaby);
			intosharebaby.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (memberCanShareList.size() > 0) {
						bySharebabyStep1Page = null;
						if (bySharebabyStep1Page == null) {
							bySharebabyStep1Page = (LinearLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_sharebaby_step1_page, null);
							member_Inside.removeAllViews();
							member_Inside.addView(bySharebabyStep1Page);
							changeShareBabyImg();
							final ImageView sharebabyStep1Babyleft = (ImageView) bySharebabyStep1Page.findViewById(R.id.sharebaby_step1_babyleft);
							final ImageView sharebabyStep1Babyright = (ImageView) bySharebabyStep1Page.findViewById(R.id.sharebaby_step1_babyright);
							/* 寶寶左 */
							sharebabyStep1Babyleft.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									if (shareBabyCount != 0) {
										shareBabyCount -= 1;
										sharebabyStep1Babyright.setVisibility(View.VISIBLE);
									}
									changeShareBabyImg();
									if (shareBabyCount == 0) {
										sharebabyStep1Babyleft.setVisibility(View.GONE);
									}
								}
							});
							sharebabyStep1Babyleft.setVisibility(View.GONE);
							/* 寶寶右 */
							sharebabyStep1Babyright.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									if (shareBabyCount != (memberCanShareList.size() - 1)) {
										shareBabyCount += 1;
										sharebabyStep1Babyleft.setVisibility(View.VISIBLE);
									}
									changeShareBabyImg();
									if (shareBabyCount == (memberCanShareList.size() - 1)) {
										sharebabyStep1Babyright.setVisibility(View.GONE);
									}
								}
							});
							if (memberCanShareList.size() == 1) {
								sharebabyStep1Babyright.setVisibility(View.GONE);
								sharebabyStep1Babyleft.setVisibility(View.GONE);
							}
							/* 取消按鈕 */
							ImageView sharebabyStep1Cancel = (ImageView) bySharebabyStep1Page.findViewById(R.id.sharebaby_step1_cancel);
							sharebabyStep1Cancel.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									intoShareBabyPage(member_Inside);
								}
							});
							/* 確定按鈕 */
							ImageView sharebabyStep1toShare = (ImageView) bySharebabyStep1Page.findViewById(R.id.sharebaby_step1_toshare);
							sharebabyStep1toShare.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									TranBabyGetCodeEvent shareBabyEvent = new TranBabyGetCodeEvent(TreeActivity.this, String.valueOf(memberCanShareList.get(shareBabyCount)) );
									shareBabyEvent.addCallback(new IEventCallback() {
										@Override
										public void result(Event event, Object result) {
											if (((TranBabyGetCodeBean) result).getResult() == 0000) {
												shareBabyCode = ((TranBabyGetCodeBean) result).getTrancode();
												Message message = mHandler.obtainMessage(INTO_SHAREBABYPAGE2, member_Inside);
												mHandler.sendMessage(message);
											}else{
												Message message = mHandler.obtainMessage(SHOW_TOAST, ((TranBabyGetCodeBean) result).getMessage());
												mHandler.sendMessage(message);
											}
										}
										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});
									KenEventManager.getInstance().execute(shareBabyEvent);
								}
							});

						} else {
							member_Inside.removeAllViews();
							member_Inside.addView(bySharebabyStep1Page);
						}
					} else {
						Message message = mHandler.obtainMessage(TreeActivity.SHOW_TOAST, "您沒有可分享的地區限定版加油寶寶，趕快去照集！");
						mHandler.sendMessage(message);
					}

				}
			});
			/*接收寶寶頁*/
			ImageView intoobtainbaby = (ImageView) bySharebabyPage.findViewById(R.id.into_obtainbaby);
			intoobtainbaby.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					byGetbabyPage = null;
					if (byGetbabyPage == null) {
						byGetbabyPage = (LinearLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_getbaby_page, null);
						member_Inside.removeAllViews();
						member_Inside.addView(byGetbabyPage);
						
						/*確定按鈕*/
						ImageView getbabypageObtain = (ImageView) byGetbabyPage.findViewById(R.id.getbabypage_obtain);
						getbabypageObtain.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								EditText getBabyPageEdittext = (EditText) byGetbabyPage.findViewById(R.id.getbabypage_edittext);
								if (!(getBabyPageEdittext.getText().toString().trim().equals(""))) {
									// 隐藏软键盘
									((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow((IBinder) findViewById(R.id.getbabypage_edittext).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "接收中…");// 秀轉轉
									mHandler.sendMessage(msg1);
									TranBabySaveCodeEvent obtainBabyEvent = new TranBabySaveCodeEvent(TreeActivity.this, getBabyPageEdittext.getText().toString());
									obtainBabyEvent.addCallback(new IEventCallback() {
										@Override
										public void result(Event event, Object result) {
											Message msg = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 取消秀轉轉
											mHandler.sendMessage(msg);
											if (((TranBabySaveCodeBean)result).getResult() == 0000) {
												Message msg3 = mHandler.obtainMessage(SHOW_ALERTDIALOG_GETBABY);
												mHandler.sendMessage(msg3);
											}else{
												Message msg2 = mHandler.obtainMessage(TreeActivity.SHOW_TOAST , ((TranBabySaveCodeBean)result).getMessage());
												mHandler.sendMessage(msg2);
											}
										}
										@Override
										public void progress(Event event, int progress, String tmpPath) {
										};
									});
									KenEventManager.getInstance().execute(obtainBabyEvent);
								}else{
									Toast.makeText(TreeActivity.this, "未輸入序號", Toast.LENGTH_SHORT).show();
								}
							}
						});
					} else {
						member_Inside.removeAllViews();
						member_Inside.addView(byGetbabyPage);
					}
					
				}
			});
			member_Inside.addView(bySharebabyPage);
		} else {
			member_Inside.addView(bySharebabyPage);
		}
	}
	
	private void intoShareBabyPage2(RelativeLayout member_Inside) {
		shareBabyCount = 0;
		member_Inside.removeAllViews();
		bySharebabyStep2Page = null;
		if (bySharebabyStep2Page == null) {
			bySharebabyStep2Page = (LinearLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.by_sharebaby_step2_page, null);
			TextView sharebabystep2char1 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char1);
			TextView sharebabystep2char2 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char2);
			TextView sharebabystep2char3 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char3);
			TextView sharebabystep2char4 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char4);
			TextView sharebabystep2char5 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char5);
			TextView sharebabystep2char6 = (TextView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_char6);
			char[] charArray = shareBabyCode.toCharArray();
			sharebabystep2char1.setText(String.valueOf(charArray[0]));
			sharebabystep2char2.setText(String.valueOf(charArray[1]));
			sharebabystep2char3.setText(String.valueOf(charArray[2]));
			sharebabystep2char4.setText(String.valueOf(charArray[3]));
			sharebabystep2char5.setText(String.valueOf(charArray[4]));
			sharebabystep2char6.setText(String.valueOf(charArray[5]));
			
			ImageView sharebabystep2tomail = (ImageView) bySharebabyStep2Page.findViewById(R.id.sharebaby_step2_tomail);
			sharebabystep2tomail.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
	            	Intent sendIntent = new Intent(Intent.ACTION_VIEW);
	            	sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
	            	sendIntent.setData(Uri.parse("abc@gmail.com"));
	            	sendIntent.putExtra(Intent.EXTRA_SUBJECT, "賺到了~好友挑了一隻地區限定寶寶要送你！");
	            	sendIntent.setType("plain/text");
	            	sendIntent.putExtra(Intent.EXTRA_TEXT, "好友剛剛送了你一隻地區限定寶寶！\n\n快到我的加油寶寶照集簿按下接收，並輸入接收序號"
	            											+ shareBabyCode +"驚喜馬上到手，行動要快~手腳太慢，朋友有可能回收唷！"
	            											+ "\n\n\n註：接收地區限定寶寶為中華電信會員特權！還不是會員？趕快加入，任何好康不錯過！");
	            	startActivity(sendIntent);
				}
			});
			
			member_Inside.addView(bySharebabyStep2Page);
		} else {
			member_Inside.addView(bySharebabyStep2Page);
		}
	}

	private void changeShareBabyImg() {
		if (babyimg!= null && babyimg.isRecycled()) {
			babyimg.recycle();
			babyimg = null;
		}
		int babyid = 0;
		if (memberCanShareList.size() > 0) {
			babyid = memberCanShareList.get(shareBabyCount);
		}
		ImageView sharebabyStep1Babyimg = (ImageView) bySharebabyStep1Page.findViewById(R.id.sharebaby_step1_babyimg);
		/* bitmap opt */
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.ALPHA_8;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
//		opt.inSampleSize = 2;
		try {
			BitmapFactory.Options.class.getField("inNativeAlloc").setBoolean(opt, true);
		} catch (IllegalArgumentException e1) {
			e1.printStackTrace();
		} catch (SecurityException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		} catch (NoSuchFieldException e1) {
			e1.printStackTrace();
		}
		try {
			Bitmap tempbitmap = BitmapFactory.decodeFile("/sdcard/.olympic/baby_" + babyid + "_1.PNG", opt);
			if (tempbitmap == null) {
//				babyimg = Helper.readBitMap(getApplicationContext(),Helper.getResId(getApplicationContext(), "drawable", "baby_" + babyid + "_1"));
			} else {
				babyimg = tempbitmap;
			}
			tempbitmap = null;
		} catch (Exception e) {
//			babyimg = Helper.readBitMap(getApplicationContext(), Helper.getResId(getApplicationContext(), "drawable", "baby_101_1"));
//			Log.e("ken", "sharebabybitmapCATCH " + babyid);
		}
		sharebabyStep1Babyimg.setImageBitmap(babyimg);
	}

	private void initPersonalLayout() {

		personal_MainLayout = (LinearLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.personal_layout, null);
		personal_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.b_1_bg_02));
		personal_MainLayout.setBackgroundDrawable(personal_bmpDrawImg);
		setLayoutView(personal_MainLayout);
		addToolbar(TreeActivity.this, 1);

		mPersonlContentListView = (ListView) personal_MainLayout.findViewById(R.id.personal_listview);
		mQueryMemberContentAdapter = new QueryMemberContentAdapter(TreeActivity.this, memberContentData, mHandler);
		mPersonlContentListView.setAdapter(mQueryMemberContentAdapter);
		mPersonlContentListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
		/* 秀轉轉 */
		ViewFlipper flipper = (ViewFlipper) findViewById(R.id.personal_layout_flipper);
		flipper.setDisplayedChild(1);

		/* 是否SHOW個人樹果實 */
		ImageView fruit = (ImageView) personal_MainLayout.findViewById(R.id.personal_fruit);
		AnimationDrawable anidraw0 = (AnimationDrawable) fruit.getDrawable();
		fruit.post(anidraw0);
		fruit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {

					Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "採果中");// 秀轉轉
					mHandler.sendMessage(msg);
					/* 採個人樹果實 */
					MemberSelfGetFruitEvent memberSelfGetFruitEvent = new MemberSelfGetFruitEvent(TreeActivity.this);
					memberSelfGetFruitEvent.addCallback(new IEventCallback() {
						@Override
						public void result(Event event, Object result) {
							Message msg4 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 取消秀轉轉
							mHandler.sendMessage(msg4);
							if (((MemberSelfGetFruitBean) result).getGiftCode() != -1) {
								Message msg = new Message();
								msg.what = SHOW_GIFTLAYOUT;
								msg.obj = result;
								msg.arg1 = 2;
								mHandler.sendMessage(msg);
								personalfruit_count -= 1;
								if (personalfruit_count == 0) {
									Message message = mHandler.obtainMessage(HIDE_PERSONALFRUIT);
									mHandler.sendMessage(message);
								}

							} else {
								Message msg2 = mHandler.obtainMessage(MSG_SHOW, ((MemberSelfGetFruitBean) result).getMessage());
								mHandler.sendMessage(msg2);
							}
						}

						@Override
						public void progress(Event event, int progress, String tmpPath) {
						}
					});

					KenEventManager.getInstance().execute(memberSelfGetFruitEvent);
				}

			}
		});

		/* 編輯個人樹姓名 */
		ImageView editMemberName = (ImageView) personal_MainLayout.findViewById(R.id.edit_membername);
		editMemberName.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					// -----------產生登入視窗--------
					final EditText editText = new EditText(TreeActivity.this);
					editText.setLayoutParams(new LayoutParams(80, 30));

					AlertDialog.Builder dlgAbout = new AlertDialog.Builder(TreeActivity.this);
					dlgAbout.setMessage("編輯個人名稱：");
					dlgAbout.setIcon(android.R.drawable.ic_dialog_info);
					dlgAbout.setCancelable(false);
					dlgAbout.setView(editText);
					dlgAbout.setPositiveButton("取消", null);
					dlgAbout.setNegativeButton("儲存", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							if (editText.getText().toString().equals("")) {
								Toast.makeText(getApplicationContext(), "名稱未輸入", Toast.LENGTH_SHORT).show();
							} else {
								Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "更改中");// 秀轉轉
								mHandler.sendMessage(msg);

								MemberModifyNameEvent memberModifyNameEvent = new MemberModifyNameEvent(TreeActivity.this, editText
										.getText().toString());
								memberModifyNameEvent.addCallback(new IEventCallback() {

									@Override
									public void result(Event event, Object result) {
										Message msg3 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 取消秀轉轉
										mHandler.sendMessage(msg3);
										if (((MemberModifyNameBean) result).getErrorCode() == 0) {
											Message msg = new Message();
											msg.what = SETTEXT_FOR_TEXTVIEW;
											msg.arg1 = R.id.member_name;

											String tempString1 = ((MemberModifyNameEvent) event).getName();
											if (tempString1.length() > 8) {
												msg.obj = tempString1.substring(0, 8) + "...";
											} else {
												msg.obj = tempString1;
											}
											tempString1 = null;
											// msg.obj =
											// ((MemberModifyNameEvent)event).getName();
											mHandler.sendMessage(msg);

											Message msg2 = mHandler.obtainMessage(SHOW_TOAST, "名稱更改成功");
											mHandler.sendMessage(msg2);
										} else {
											Message msg2 = mHandler.obtainMessage(SHOW_TOAST, "網路連線異常，名稱更改失敗。");
											mHandler.sendMessage(msg2);
										}
									}

									@Override
									public void progress(Event event, int progress, String tmpPath) {
									}
								});
								KenEventManager.getInstance().execute(memberModifyNameEvent);
							}
						}
					});
					dlgAbout.show();
				}

			}
		});

		/* 跳出式留言 */
		mPersonlContentListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				/* flag擋重複 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {

					if (treeSinglMsgPop != null) {
						treeSinglMsgPop.setVisibility(View.GONE);
						treeSinglMsgPop.removeAllViews();
						treeSinglMsgPop = null;
					}
					LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
					treeSinglMsgPop = (RelativeLayout) inflater.inflate(R.layout.treesingle_poprow, null);
					TextView treeSinglName = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_name);
					TextView treeSinglDescription = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_description);
					TextView treeSinglDescDate = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_desc_date);
					TextView treeSinglSpname = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_spname);

					String tempString = memberContentData.get(position).getItemName();
					if (tempString.length() > 4) {
						treeSinglName.setText(tempString.substring(0, 4) + "...");
					} else {
						treeSinglName.setText(tempString);
					}

					treeSinglDescription.setText(memberContentData.get(position).getItemDescription());
					Date date = new Date(memberContentData.get(position).getItemDate() * 1000L);
					DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					treeSinglDescDate.setText(dateFormat.format(date));
					treeSinglSpname.setText(memberContentData.get(position).getTreeName());
					// LinearLayout absoluteLayout = new LinearLayout
					addContentView(treeSinglMsgPop, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
					personalMsgPopisOpen = true;

					ImageView cancel = (ImageView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_cancel);
					cancel.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							treeSinglMsgPop.setVisibility(View.GONE);
							treeSinglMsgPop.removeAllViews();
							treeSinglMsgPop = null;
							personalMsgPopisOpen = false;
						}
					});
				}

			}
		});

	}

	private void initLayout2(final int position) {
		/* 選手頁 */
		if (layout1_b == null) {
			layout1_b = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.treeactlayout2, null);
		}
		setLayoutView(layout1_b);
		// Cliff add
		((Olympic) this.getApplication()).mPageIndex = Olympic.PageIndex.TREE_CONTESTANY;
		//
		addToolbar(TreeActivity.this, 0);
		treeSingleListData.clear();
		if (mSingleTreeListView == null) {
			mSingleTreeListView = (RefreshableListView) layout1_b.findViewById(R.id.tree_msglistview);
			mMemberTreeAdapter = new QueryTreeAdapter(TreeActivity.this, treeSingleListData, mHandler);
			mSingleTreeListView.setAdapter(mMemberTreeAdapter);
			mSingleTreeListView.setDivider(new ColorDrawable(Color.TRANSPARENT));// 去除listview分隔線
		}
		/* 秀轉轉 */
		ViewFlipper flipper = (ViewFlipper) findViewById(R.id.layout2_flipper);
		flipper.setDisplayedChild(1);
		/* 跑馬燈 */
		TextView newsList = (TextView) findViewById(R.id.scrolling_text);
		newsList.setFocusable(true);
		newsList.setSelected(true);
		newsList.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					if (URL_NEWLIST != null) {
						Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_NEWLIST));
						startActivity(it);
					}
				}
			}
		});

		/* 背景圖 */
		// BitmapDrawable layout1b_bmpDrawImg = null;
		switch (treeListData.get(position).getTreeType()) {
		case 1:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype1));
			break;
		case 2:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype2));
			break;
		case 3:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype3));
			break;
		case 4:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype4));
			break;
		case 5:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype5));
			break;
		case 6:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype6));
			break;
		case 7:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype7));
			break;
		case 8:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype8));
			break;
		case 9:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype9));
			break;
		case 10:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype10));
			break;
		case 11:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype11));
			break;
		case 12:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype12));
			break;
		case 13:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype13));
			break;
		case 14:
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype14));
			break;
		}
		if (layout1b_bmpDrawImg == null) {
			layout1b_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg_treetype1));
		}
		layout1_b.setBackgroundDrawable(layout1b_bmpDrawImg);
		// layout1b_bmpDrawImg = null;

		TextView layout2Name = (TextView) layout1_b.findViewById(R.id.layout2_name);
		layout2Name.setText(treeListData.get(position).getTreeName());
		TextView layout2Score = (TextView) layout1_b.findViewById(R.id.layout2_score);
		if (treeListData.get(position).getTodayGet() == 1) {
			layout2Score.setText("今日已採果");
			TextView layout2Text = (TextView) layout1_b.findViewById(R.id.layout2_text);
			layout2Text.setVisibility(View.GONE);
		} else {
			layout2Score.setText(Integer.toString(treeListData.get(position).getTodayScore()));
		}

		ImageView layout2Tree = (ImageView) layout1_b.findViewById(R.id.layout2_tree);
		if (treeListData.get(position).getTotalScore() >= 1000 && treeListData.get(position).getTotalScore() < 3000) {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_02));
		} else if (treeListData.get(position).getTotalScore() >= 3000 && treeListData.get(position).getTotalScore() < 500) {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_03));
		} else if (treeListData.get(position).getTotalScore() >= 5000 && treeListData.get(position).getTotalScore() < 10000) {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_04));
		} else if (treeListData.get(position).getTotalScore() >= 10000 && treeListData.get(position).getTotalScore() < 15000) {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_04));
		} else if (treeListData.get(position).getTotalScore() >= 15000) {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_06));
		} else {
			layout2Tree.setImageBitmap(Helper.readBitMapforBG(getApplicationContext(), R.drawable.tree_01));
		}

		ImageView layout2_spman = (ImageView) layout1_b.findViewById(R.id.sportsman_icon);
		try {
			Bitmap temp = Helper.readBitMap(getApplicationContext(), Helper.getResId(getApplicationContext(), "drawable", "tree_"+ treeListData.get(position).getTreeId() +"_2"));
			if (temp != null) {
				layout2_spman.setImageBitmap(temp);
			}else{
				layout2_spman.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.sportsman_def));
			}
			temp = null;
		} catch (Exception e) {
			layout2_spman.setImageBitmap(Helper.readBitMap(getApplicationContext(), R.drawable.sportsman_def));
		}

		/** 下拉更新 */
		mSingleTreeListView.setOnRefreshListener(new OnRefreshListener() {
			@Override
			public void onRefresh() {
				QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this, treeListData.get(position)
						.getTreeId());
				mGetTreeSingleEvent.addCallback(new IEventCallback() {
					@Override
					public void result(Event event, Object result) {
						treeSingleListData.clear();
						treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
						Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
						mHandler.sendMessage(msg);
					}

					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(mGetTreeSingleEvent);
			}
		});

		/* 跳出式留言 */
		mSingleTreeListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				/* flag擋重複開啟 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					if (treeSinglMsgPop != null) {
						treeSinglMsgPop.setVisibility(View.GONE);
						treeSinglMsgPop.removeAllViews();
						treeSinglMsgPop = null;
					}
					LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
					treeSinglMsgPop = (RelativeLayout) inflater.inflate(R.layout.treesingle_poprow, null);
					TextView treeSinglName = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_name);
					TextView treeSinglDescription = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_description);
					TextView treeSinglDescDate = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_desc_date);
					TextView treeSinglSpname = (TextView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_spname);

					String tempString = treeSingleListData.get(position - 1).getItemName();
					if (tempString.length() > 8) {
						treeSinglName.setText(tempString.substring(0, 8) + "...");
					} else {
						treeSinglName.setText(tempString);
					}

					treeSinglDescription.setText(treeSingleListData.get(position - 1).getItemDescription());
					Date date = new Date(treeSingleListData.get(position - 1).getItemDate() * 1000L);
					DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					treeSinglDescDate.setText(dateFormat.format(date));
					treeSinglSpname.setText(treeSingleListData.get(position - 1).getTreeName());
					// LinearLayout absoluteLayout = new LinearLayout
					addContentView(treeSinglMsgPop, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
					sportsmanMsgPopisOpen = true;
					ImageView cancel = (ImageView) treeSinglMsgPop.findViewById(R.id.tree_singlpop_cancel);
					cancel.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							treeSinglMsgPop.setVisibility(View.GONE);
							treeSinglMsgPop.removeAllViews();
							treeSinglMsgPop = null;
							sportsmanMsgPopisOpen = false;
						}
					});
				}

			}
		});
		/* 採收果實 */
		ImageView getfruit = (ImageView) findViewById(R.id.btn_getfruit);
		if (treeListData.get(position).getFruitStart() == 0) {
			getfruit.setVisibility(View.GONE);
		} else {
			getfruit.setVisibility(View.VISIBLE);
			AnimationDrawable anidraw0 = (AnimationDrawable) getfruit.getDrawable();
			getfruit.post(anidraw0);
			getfruit.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					/* popraw開啟時無法點擊 */
					if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
						/* 讀取sn來確定是否登入過 */
						if (KenEventManager.getInstance().getCHTsn() == 0) {
							/* 沒有sn未登入過載入燈入頁 */
							loginPage = (RelativeLayout) LayoutInflater.from(TreeActivity.this)
									.inflate(R.layout.by_login_pertreepage, null);
							setLayoutView(loginPage);
							/* 登入背景說明頁 */
							showLoginInfo();

							// // Cliff add
							// ((Olympic)TreeActivity.this.getApplication()).mPageIndex
							// = Olympic.PageIndex.TREE_CONTESTANY_LOGIN;
							// //
							/* 設定頁面title */
							TextView title = (TextView) loginPage.findViewById(R.id.login_titlekind);
							title.setText("搶收果實");

							/* 返回按鈕 */
							ImageView btn_back = (ImageView) findViewById(R.id.perpage_back);
							btn_back.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									if (!loginInfoPageisOpen) {
										// 隐藏软键盘
										((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
												findViewById(R.id.perpage_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

										// Cliff Modified...
										gotoTabTree();
										//
										loginPage = null;
									}
								}
							});

							/* 加入會員按鈕 */
							ImageView btn_addMember = (ImageView) findViewById(R.id.perpage_addmember);
							btn_addMember.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
								}
							});
							/* 忘記密碼按鈕 */
							ImageView btn_forGetpass = (ImageView) findViewById(R.id.perpage_forgetpss);
							btn_forGetpass.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
								}
							});
							/* 登入按鈕 */
							ImageView btn_Login = (ImageView) findViewById(R.id.perpage_login);
							btn_Login.setOnClickListener(new OnClickListener() {
								@Override
								public void onClick(View v) {
									// =============
									EditText account = (EditText) findViewById(R.id.perpage_account);
									EditText password = (EditText) findViewById(R.id.perpage_password);

									if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
									if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
									/* 判斷欄位是否有未填 */
									if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
											&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
										// 隐藏软键盘
										((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
												password.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

										/* 轉轉 */
										Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
										mHandler.sendMessage(msg);

										PersonalBean.getInstance().setAccount(account.getText().toString());
										PersonalBean.getInstance().setPassword(password.getText().toString());
										LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
										loginEvent.addCallback(new IEventCallback() {
											@Override
											public void result(Event event, Object result) {

												Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
												mHandler.sendMessage(msg2);

												if (((PersonalBean) result).getChtsn() == 0 || ((PersonalBean) result).getUserType() == -1) {
													// TODO show障密錯誤
													Message msg = mHandler.obtainMessage(MSG_SHOW,
															((PersonalBean) result).getLoginMessage());
													mHandler.sendMessage(msg);
													if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
												} else {
													/* 儲存sn */
													KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
													/* 儲存帳號 */
													KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
													/* 儲存nickname */
													KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
													/* 儲存usertype */
													KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
													if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}

													/* 推播更新 */
													UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null,
															((Olympic) getApplicationContext()).getRegistrationID());
													updPushTokenEvent.addCallback(new IEventCallback() {

														@Override
														public void result(Event event, Object result) {
															if (result instanceof UpdPushTokenBean) {
																if (((UpdPushTokenBean) result).getResult() == 0000) {
																	if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
																	// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
																}
															} else if (result == null) {
																if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
															}

														}

														@Override
														public void progress(Event event, int progress, String tmpPath) {
														}
													});
													KenEventManager.getInstance().execute(updPushTokenEvent);

													/* 設定layout */
													loginPage = null;
													Message msg = new Message();
													msg.what = SET_LAYOUTVIEW;
													msg.arg1 = 1;
													mHandler.sendMessage(msg);
													/* 秀選手樹 */
													msg = mHandler.obtainMessage(INITLAYOUT2, position, 0);
													mHandler.sendMessage(msg);
													/* 更新跑馬燈 */
													NewsListEvent newsListEvent = new NewsListEvent(TreeActivity.this, treeListData.get(
															position).getTreeId());
													newsListEvent.addCallback(new IEventCallback() {
														@Override
														public void result(Event event, Object result) {

															String newsString = "";
															List<NewsListBean> data = (List<NewsListBean>) result;
															for (int i = 0; i < data.size(); i++) {
																newsString = "　　　" + data.get(i).getCont() + "　　　";
																URL_NEWLIST = data.get(i).getUrl();
															}
															newsString += newsString;
															Message msg = new Message();
															msg.what = SETTEXT_FOR_TEXTVIEW;
															msg.arg1 = R.id.scrolling_text;
															msg.obj = newsString;
															mHandler.sendMessage(msg);
														}

														@Override
														public void progress(Event event, int progress, String tmpPath) {
														}
													});
													KenEventManager.getInstance().execute(newsListEvent);

													QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(
															TreeActivity.this, treeListData.get(position).getTreeId());
													mGetTreeSingleEvent.addCallback(new IEventCallback() {
														@Override
														public void result(Event event, Object result) {
															treeSingleListData.clear();
															treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
															Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
															mHandler.sendMessage(msg);

														}

														@Override
														public void progress(Event event, int progress, String tmpPath) {
														}
													});
													KenEventManager.getInstance().execute(mGetTreeSingleEvent);
												}

											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {

											}
										});

										/* 加入採果EVENT為SubEvent */
										CHTContentUploadEvent chtContentUploadEvent = new CHTContentUploadEvent(TreeActivity.this,
												treeListData.get(position).getTreeId());
										chtContentUploadEvent.addCallback(new IEventCallback() {
											@Override
											public void result(Event event, Object result) {

												if (((CHTContentUploadBean) result).getGiftCode() != -1) {
													Message msg = new Message();
													msg.what = SHOW_GIFTLAYOUT;
													msg.obj = result;
													msg.arg1 = 1;
													mHandler.sendMessage(msg);
												} else {
													Message msg2 = mHandler.obtainMessage(MSG_SHOW,
															((CHTContentUploadBean) result).getMessage());
													mHandler.sendMessage(msg2);
												}
											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});

										loginEvent.addSubEvent(chtContentUploadEvent);

										KenEventManager.getInstance().execute(loginEvent);
									} else {
										Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
									}

									// ===============
								}
							});

						} else {
							Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "採果中");// 秀轉轉
							mHandler.sendMessage(msg1);

							CHTContentUploadEvent chtContentUploadEvent = new CHTContentUploadEvent(TreeActivity.this, treeListData.get(
									position).getTreeId());
							chtContentUploadEvent.addCallback(new IEventCallback() {
								@Override
								public void result(Event event, Object result) {

									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL, "採果中");// 取消轉轉
									mHandler.sendMessage(msg1);

									if (((CHTContentUploadBean) result).getGiftCode() != -1) {
										Message msg = new Message();
										msg.what = SHOW_GIFTLAYOUT;
										msg.obj = result;
										msg.arg1 = 1;
										mHandler.sendMessage(msg);
									} else {
										Message msg2 = mHandler.obtainMessage(MSG_SHOW, ((CHTContentUploadBean) result).getMessage());
										mHandler.sendMessage(msg2);
									}
								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {
								}
							});

							KenEventManager.getInstance().execute(chtContentUploadEvent);
						}
					}

				}
			});
		}

		/* 更新跑馬燈 */
		NewsListEvent newsListEvent = new NewsListEvent(TreeActivity.this, treeListData.get(position).getTreeId());
		newsListEvent.addCallback(new IEventCallback() {
			@Override
			public void result(Event event, Object result) {

				String newsString = "";
				List<NewsListBean> data = (List<NewsListBean>) result;
				for (int i = 0; i < data.size(); i++) {
					newsString = "　　　　　" + data.get(i).getCont() + "　　　　　";
				}
				newsString += newsString;
				newsString += newsString;
				Message msg = new Message();
				msg.what = SETTEXT_FOR_TEXTVIEW;
				msg.arg1 = R.id.scrolling_text;
				msg.obj = newsString;
				mHandler.sendMessage(msg);
			}

			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(newsListEvent);

	}

	/** AR返回 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (requestCode == GETBABY_RESULT && resultCode == GETBABY_RESULT) {
			if (IS_DEBUG) {Log.d("ken", "GETBABY_RESULT");}
			// ==========
			/* 讀取sn來確定是否登入過 */
			if (KenEventManager.getInstance().getCHTsn() == 0 && KenEventManager.getInstance().getGuestname().equals("")) {

				// // Cliff add
				// ((Olympic)TreeActivity.this.getApplication()).mPageIndex =
				// Olympic.PageIndex.AR_LOGIN;
				// //

				/* 沒有sn未登入過 */
				LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
				View login = inflater.inflate(R.layout.by_multi_login_page, null);
				setLayoutView(login);

				/* 登入背景說明頁 */
				showLoginInfo();

				/* 返回按鈕 */
				ImageView btn_back = (ImageView) findViewById(R.id.multilogpage_back);
				btn_back.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						if (!loginInfoPageisOpen) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									findViewById(R.id.multilogin_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
							String[] title = { "是", "否" };
							Helper.ShowMessage(TreeActivity.this, "", "請確認是否離開登入頁", 2, title, new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog, int which) {
									cleanerLayout();
									setBackgroundLayout();
									((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
								}
							}, null, new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog, int which) {
								}
							});

						}
					}
				});

				/* 加入會員按鈕 */
				ImageView btn_addMember = (ImageView) findViewById(R.id.multilogpage_addmember);
				btn_addMember.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
					}
				});
				/* 忘記密碼按鈕 */
				ImageView btn_forGetpass = (ImageView) findViewById(R.id.multilogpage_forgetpss);
				btn_forGetpass.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
					}
				});
				/* 登入按鈕 */
				ImageView btn_Login = (ImageView) findViewById(R.id.multilogpage_login);
				btn_Login.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// =============
						EditText account = (EditText) findViewById(R.id.multilogin_account);
						EditText password = (EditText) findViewById(R.id.multilogin_password);

						if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
						if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
						/* 判斷欄位是否有未填 */
						if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
								&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									password.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

							/* 轉轉 */
							Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
							mHandler.sendMessage(msg);

							PersonalBean.getInstance().setAccount(account.getText().toString());
							PersonalBean.getInstance().setPassword(password.getText().toString());
							LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
							loginEvent.addCallback(new IEventCallback() {
								@Override
								public void result(Event event, Object result) {
									/* 取消轉轉 */
									Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
									mHandler.sendMessage(msg2);

									// 判斷是否登入成功
									if (((PersonalBean) result).getChtsn() == 0) {
										Message msg = mHandler.obtainMessage(MSG_SHOW, ((PersonalBean) result).getLoginMessage());
										mHandler.sendMessage(msg);
										if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
									} else {
										/* 儲存sn */
										KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
										/* 儲存帳號 */
										KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
										/* 儲存nickname */
										KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
										/* 儲存usertype */
										KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
										if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}

										/* 推播更新 */
										UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null,
												((Olympic) getApplicationContext()).getRegistrationID());
										updPushTokenEvent.addCallback(new IEventCallback() {

											@Override
											public void result(Event event, Object result) {
												if (result instanceof UpdPushTokenBean) {
													if (((UpdPushTokenBean) result).getResult() == 0000) {
														if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
														// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
													}
												} else if (result == null) {
													if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
												}

											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(updPushTokenEvent);
										
										Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_SHOW, "載入留言頁中...");
										mHandler.sendMessage(message);
										MemberCanLikeEvent canLikeEvent = new MemberCanLikeEvent(TreeActivity.this);
										canLikeEvent.addCallback(new IEventCallback() {
											@Override
											public void result(Event event, Object result) {
												Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_CANCEL);
												mHandler.sendMessage(message);
												if (!(result instanceof String && ((String) result).equals("ERROR"))) {
													if (((ArrayList<TreeAllBean>) result).size() == 0){
														// 切回照集
														Intent it = new Intent();
														it.setClass(TreeActivity.this, ARExampleActivity.class);
														startActivityForResult(it, GETBABY_RESULT);
														Message msg = mHandler.obtainMessage(SHOW_TOAST,"您已為所有選手加油過了唷！歡迎您一小時候再來為選手照集加油！");
														mHandler.sendMessage(msg);
													} else{
														canLikeTreeListData.clear();
														canLikeTreeListData.addAll((Collection<? extends TreeAllBean>) result);
														Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 9, 0, PersonalBean.getInstance().getNickname());
														mHandler.sendMessage(msg);
													}
													
												} else {
													// 切回照集
													Intent it = new Intent();
													it.setClass(TreeActivity.this, ARExampleActivity.class);
													startActivityForResult(it, GETBABY_RESULT);
													Message msg = mHandler.obtainMessage(SHOW_TOAST,"網路異常返回照集");
													mHandler.sendMessage(msg);
												}
											}
											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(canLikeEvent);

									}

								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {

								}
							});

							KenEventManager.getInstance().execute(loginEvent);
						} else {
							Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
						}

						// ===============
					}
				});

				/* 訪客登入 */
				ImageView btn_guestLogin = (ImageView) findViewById(R.id.multilogpage_guestlogin);
				btn_guestLogin.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 9, 0, PersonalBean.getInstance().getGuestname());
						initGuestLogin(msg, 9);
					}
				});

			}
			/* 有sn登入過載入留言頁 */
			else if (KenEventManager.getInstance().getCHTsn() != 0) {
				Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_SHOW, "載入留言頁中...");
				mHandler.sendMessage(message);
				MemberCanLikeEvent canLikeEvent = new MemberCanLikeEvent(TreeActivity.this);
				canLikeEvent.addCallback(new IEventCallback() {
					@Override
					public void result(Event event, Object result) {
						Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_CANCEL);
						mHandler.sendMessage(message);
						if (!(result instanceof String && ((String) result).equals("ERROR"))) {
							 if (((ArrayList<TreeAllBean>) result).size() == 0){
									// 切回照集
									Intent it = new Intent();
									it.setClass(TreeActivity.this, ARExampleActivity.class);
									startActivityForResult(it, GETBABY_RESULT);
									Message msg = mHandler.obtainMessage(SHOW_TOAST,"您已為所有選手加油過了唷！歡迎您一小時候再來為選手照集加油！");
									mHandler.sendMessage(msg);
							} else{
								canLikeTreeListData.clear();
								canLikeTreeListData.addAll((Collection<? extends TreeAllBean>) result);
								Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 9, 0, PersonalBean.getInstance().getNickname());
								mHandler.sendMessage(msg);
							}
						} else {
							// 切回照集
							Intent it = new Intent();
							it.setClass(TreeActivity.this, ARExampleActivity.class);
							startActivityForResult(it, GETBABY_RESULT);
							Message msg = mHandler.obtainMessage(SHOW_TOAST,"網路異常返回照集");
							mHandler.sendMessage(msg);
						}
					}
					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(canLikeEvent);
			}
			/* 有訪客登入過載入留言頁 */
			else if (KenEventManager.getInstance().getCHTsn() == 0 && !(KenEventManager.getInstance().getGuestname().equals(""))) {
				Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_SHOW, "載入留言頁中...");
				mHandler.sendMessage(message);
				VisitorCanLikeEvent canLikeEvent = new VisitorCanLikeEvent(TreeActivity.this);
				canLikeEvent.addCallback(new IEventCallback() {
					@Override
					public void result(Event event, Object result) {
						Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_CANCEL);
						mHandler.sendMessage(message);
						if (!(result instanceof String && ((String) result).equals("ERROR"))) {
							if (((ArrayList<TreeAllBean>) result).size() == 0){
								// 切回照集
								Intent it = new Intent();
								it.setClass(TreeActivity.this, ARExampleActivity.class);
								startActivityForResult(it, GETBABY_RESULT);
								Message msg = mHandler.obtainMessage(SHOW_TOAST,"您已為所有選手加油過了唷！歡迎您一小時候再來為選手照集加油！");
								mHandler.sendMessage(msg);
							} else{
								canLikeTreeListData.clear();
								canLikeTreeListData.addAll((Collection<? extends TreeAllBean>) result);
								Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 9, 0, PersonalBean.getInstance().getGuestname());
								mHandler.sendMessage(msg);
							}
						} else {
							// 切回照集
							Intent it = new Intent();
							it.setClass(TreeActivity.this, ARExampleActivity.class);
							startActivityForResult(it, GETBABY_RESULT);
							Message msg = mHandler.obtainMessage(SHOW_TOAST,"網路異常返回照集");
							mHandler.sendMessage(msg);
						}
					}
					@Override
					public void progress(Event event, int progress, String tmpPath) {
					}
				});
				KenEventManager.getInstance().execute(canLikeEvent);
			}

		}
		/*-------FB_CALLBACK--------------------------------------------------------------------*/
		this.facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
		/*-----------------------------------------------------------------------------------*/
		super.onActivityResult(requestCode, resultCode, data);
	}

	/** 留言頁初始 */
	private void initMsgAddPage(String name) {

		LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
		msgadd = (RelativeLayout) inflater.inflate(R.layout.by_msg_add_page, null);
		setLayoutView(msgadd);
		/* 留言攔 */
		final EditText editMsg = (EditText) msgadd.findViewById(R.id.edit_msg);
		/* 留言名稱 */
		// Message msg = mHandler.obtainMessage(SETTEXT_FOR_TEXTVIEW,
		// R.id.msgadd_name, 0, name);
		// mHandler.sendMessage(msg);
		TextView nameTextview = (TextView) msgadd.findViewById(R.id.msgadd_name);
		nameTextview.setText(name);

		Spinner spinner = (Spinner) msgadd.findViewById(R.id.spinnner);
		String[] allsportmanArray = new String[canLikeTreeListData.size()];
		for (int i = 0; i < allsportmanArray.length; i++) {
			allsportmanArray[i] = canLikeTreeListData.get(i).getTreeName();
		}

		ArrayAdapter<String> spnarrayAdapter = new ArrayAdapter<String>(TreeActivity.this, android.R.layout.simple_spinner_item,
				allsportmanArray);
		spnarrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(spnarrayAdapter);
		spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				spinerselect = arg2;
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				spinerselect = 0;
			}
		});

		/* 加油打氣按鈕 */
		ImageView btn_mbContentUpload = (ImageView) msgadd.findViewById(R.id.btn_mbcontentupload);
		btn_mbContentUpload.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				/* 如果有輸入留言才繼續 */
				if (!(editMsg.getText().toString().trim().equals(""))) {
					// 隐藏软键盘
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.edit_msg)
							.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

					if (IS_DEBUG) {Log.d("ken", "會員留言上傳");}
					/* 會員留言 */
					if (PersonalBean.getInstance().getChtsn() != 0) {
						Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "留言上傳中");// 秀轉轉
						mHandler.sendMessage(msg1);

						Olympic olympic = (Olympic) getApplicationContext();
						/* 先產生GAMECODE */
						GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic
								.getBabyCatchId());
						guestRecordUploadEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								Olympic olympic = (Olympic) getApplicationContext();
								olympic.setGameCode("");
								if (((GuestRecordUploadBean) result).getResult() == 0000) {
									/* 再上傳留言 */
									MemberContentUploadEvent memberContentUploadEvent = new MemberContentUploadEvent(TreeActivity.this,
											canLikeTreeListData.get(spinerselect).getTreeId(), ((GuestRecordUploadBean) result).getGameCode(),
											PersonalBean.getInstance().getNickname(), editMsg.getText().toString());
									memberContentUploadEvent.addCallback(new IEventCallback() {
										@Override
										public void result(Event event, Object result) {
											Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
											mHandler.sendMessage(msg1);
											Message msg;
											switch (((MemberContentUploadBean) result).getResult()) {
											case 9999:
												msg = mHandler.obtainMessage(MSGUPLOAD_ERROR);
												mHandler.sendMessage(msg);
												break;
											case 0000:
												msgadd = null;
												msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
												mHandler.sendMessage(msg);

												Message msg2 = mHandler.obtainMessage(MSG_SHOW, "留言成功");
												mHandler.sendMessage(msg2);

												/** 送出加油的流水密碼 */
												if (((MemberContentUploadBean) result).getGiftId() > 0) {
													toMailMessageGoldCode(((MemberContentUploadBean) result).getGiftNumber());
												}
												/* 查詢選手樹 */
												QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
														canLikeTreeListData.get(spinerselect).getTreeId());
												mGetTreeSingleEvent.addCallback(new IEventCallback() {
													@Override
													public void result(Event event, Object result) {
														treeSingleListData.clear();
														treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
														Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
														mHandler.sendMessage(msg);

													}

													@Override
													public void progress(Event event, int progress, String tmpPath) {
													}
												});
												KenEventManager.getInstance().execute(mGetTreeSingleEvent);
												break;
											}
										}

										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});

									KenEventManager.getInstance().execute(memberContentUploadEvent);
								} else {
									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
									mHandler.sendMessage(msg1);
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});

						KenEventManager.getInstance().execute(guestRecordUploadEvent);
					}
					/* 訪客留言 */
					else if (Integer.valueOf(PersonalBean.getInstance().getGuestmobile()) != 0
							&& PersonalBean.getInstance().getChtsn() == 0) {
						Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "留言上傳中");// 秀轉轉
						mHandler.sendMessage(msg1);

						Olympic olympic = (Olympic) getApplicationContext();
						/* 先產生GAMECODE */
						GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic
								.getBabyCatchId());
						guestRecordUploadEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								Olympic olympic = (Olympic) getApplicationContext();
								olympic.setGameCode("");
								if (((GuestRecordUploadBean) result).getResult() == 0000) {

									/* 訪客留言上傳 */
									GuestContentUploadEvent guestContentUploadEvent = new GuestContentUploadEvent(TreeActivity.this,
											canLikeTreeListData.get(spinerselect).getTreeId(), ((GuestRecordUploadBean) result).getGameCode(),
											KenEventManager.getInstance().getGuestname(), editMsg.getText().toString(), KenEventManager
													.getInstance().getGuestMobile(), 1);
									guestContentUploadEvent.addCallback(new IEventCallback() {

										@Override
										public void result(Event event, Object result) {
											Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
											mHandler.sendMessage(msg1);
											Message msg;

											switch (((GuestContentUploadBean) result).getResult()) {
											case 9999:
												msg = mHandler.obtainMessage(MSGUPLOAD_ERROR);
												mHandler.sendMessage(msg);
												break;
											case 0000:
												msgadd = null;
												msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
												mHandler.sendMessage(msg);

												/** 送出加油的流水密碼 */
												if (((GuestContentUploadBean) result).getGiftId() > 0) {
													toMailMessageGoldCode(((GuestContentUploadBean) result).getGiftNumber());
												}
												Message msg2 = mHandler.obtainMessage(MSG_SHOW, "留言成功");
												mHandler.sendMessage(msg2);
												QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
														canLikeTreeListData.get(spinerselect).getTreeId());
												mGetTreeSingleEvent.addCallback(new IEventCallback() {
													@Override
													public void result(Event event, Object result) {
														treeSingleListData.clear();
														treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
														Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
														mHandler.sendMessage(msg);

													}

													@Override
													public void progress(Event event, int progress, String tmpPath) {
													}
												});
												KenEventManager.getInstance().execute(mGetTreeSingleEvent);
												break;
											}
										}

										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});
									KenEventManager.getInstance().execute(guestContentUploadEvent);
								} else {
									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
									mHandler.sendMessage(msg1);
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});

						KenEventManager.getInstance().execute(guestRecordUploadEvent);
					}
				} else {
					Toast.makeText(TreeActivity.this, "未輸入留言內容", Toast.LENGTH_SHORT).show();
				}

			}
		});

		/* 加油打氣FB按鈕 */
		ImageView btn_mbFbContentUpload = (ImageView) msgadd.findViewById(R.id.btn_mbfbcontentupload);
		btn_mbFbContentUpload.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				/* 如果有輸入留言才繼續 */
				if (!(editMsg.getText().toString().trim().equals(""))) {
					// 隐藏软键盘
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.edit_msg)
							.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

					if (IS_DEBUG) {Log.d("ken", "會員留言上傳");}
					/* 會員留言 */
					if (PersonalBean.getInstance().getChtsn() != 0) {
						Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "留言上傳中");// 秀轉轉
						mHandler.sendMessage(msg1);

						Olympic olympic = (Olympic) getApplicationContext();
						/* 先產生GAMECODE */
						GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic
								.getBabyCatchId());
						guestRecordUploadEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								Olympic olympic = (Olympic) getApplicationContext();
								olympic.setGameCode("");
								if (((GuestRecordUploadBean) result).getResult() == 0000) {
									/* 再上傳留言 */
									MemberContentUploadEvent memberContentUploadEvent = new MemberContentUploadEvent(TreeActivity.this,
											canLikeTreeListData.get(spinerselect).getTreeId(), ((GuestRecordUploadBean) result).getGameCode(),
											PersonalBean.getInstance().getNickname(), editMsg.getText().toString());
									memberContentUploadEvent.addCallback(new IEventCallback() {
										@Override
										public void result(Event event, Object result) {
											Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
											mHandler.sendMessage(msg1);
											Message msg;
											switch (((MemberContentUploadBean) result).getResult()) {
											case 9999:
												msg = mHandler.obtainMessage(MSGUPLOAD_ERROR);
												mHandler.sendMessage(msg);
												break;
											case 0000:
												msgadd = null;
												msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
												mHandler.sendMessage(msg);

												/** 送出加油的流水密碼 */
												if (((MemberContentUploadBean) result).getGiftId() > 0) {
													toMailMessageGoldCode(((MemberContentUploadBean) result).getGiftNumber());
												}
												Message msg2 = mHandler.obtainMessage(MSG_SHOW, "留言成功");
												mHandler.sendMessage(msg2);

												/** 同步臉書 */
												hasMessage = true;
												Message msg3 = mHandler.obtainMessage(FB_WALLPOST,((MemberContentUploadEvent) event).getContent());
												mHandler.sendMessage(msg3);
												/* 查詢選手樹 */
												QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
														canLikeTreeListData.get(spinerselect).getTreeId());
												mGetTreeSingleEvent.addCallback(new IEventCallback() {
													@Override
													public void result(Event event, Object result) {
														treeSingleListData.clear();
														treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
														Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
														mHandler.sendMessage(msg);

													}

													@Override
													public void progress(Event event, int progress, String tmpPath) {
													}
												});
												KenEventManager.getInstance().execute(mGetTreeSingleEvent);
												break;
											}
										}

										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});

									KenEventManager.getInstance().execute(memberContentUploadEvent);
								} else {
									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
									mHandler.sendMessage(msg1);
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});

						KenEventManager.getInstance().execute(guestRecordUploadEvent);
					}
					/* 訪客留言 */
					else if (!(KenEventManager.getInstance().getGuestMobile().equals("")) && PersonalBean.getInstance().getChtsn() == 0) {
						Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "留言上傳中");// 秀轉轉
						mHandler.sendMessage(msg1);

						Olympic olympic = (Olympic) getApplicationContext();
						/* 先產生GAMECODE */
						GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic
								.getBabyCatchId());
						guestRecordUploadEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								Olympic olympic = (Olympic) getApplicationContext();
								olympic.setGameCode("");
								if (((GuestRecordUploadBean) result).getResult() == 0000) {
									/* 訪客上傳 */
									GuestContentUploadEvent guestContentUploadEvent = new GuestContentUploadEvent(TreeActivity.this,
											canLikeTreeListData.get(spinerselect).getTreeId(), ((GuestRecordUploadBean) result).getGameCode(),
											KenEventManager.getInstance().getGuestname(), editMsg.getText().toString(), KenEventManager
													.getInstance().getGuestMobile(), 1);
									guestContentUploadEvent.addCallback(new IEventCallback() {

										@Override
										public void result(Event event, Object result) {
											Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
											mHandler.sendMessage(msg1);
											Message msg;

											switch (((GuestContentUploadBean) result).getResult()) {
											case 9999:
												msg = mHandler.obtainMessage(MSGUPLOAD_ERROR);
												mHandler.sendMessage(msg);
												break;
											case 0000:
												msgadd = null;
												msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
												mHandler.sendMessage(msg);

												/** 送出加油的流水密碼 */
												if (((GuestContentUploadBean) result).getGiftId() > 0) {
													toMailMessageGoldCode(((GuestContentUploadBean) result).getGiftNumber());
												}
												Message msg2 = mHandler.obtainMessage(MSG_SHOW, "留言成功");
												mHandler.sendMessage(msg2);

												/** 同步臉書 */
												hasMessage = true;
												Message msg3 = mHandler.obtainMessage(FB_WALLPOST,((GuestContentUploadEvent) event).getContent());
												mHandler.sendMessage(msg3);
												QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
														canLikeTreeListData.get(spinerselect).getTreeId());
												mGetTreeSingleEvent.addCallback(new IEventCallback() {
													@Override
													public void result(Event event, Object result) {
														treeSingleListData.clear();
														treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
														Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
														mHandler.sendMessage(msg);

													}

													@Override
													public void progress(Event event, int progress, String tmpPath) {
													}
												});
												KenEventManager.getInstance().execute(mGetTreeSingleEvent);
												break;
											}
										}

										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});
									KenEventManager.getInstance().execute(guestContentUploadEvent);
								} else {
									Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
									mHandler.sendMessage(msg1);
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});

						KenEventManager.getInstance().execute(guestRecordUploadEvent);
					}
				} else {
					Toast.makeText(TreeActivity.this, "未輸入留言內容", Toast.LENGTH_SHORT).show();
				}

			}
		});

		/* 按讚打氣按鈕 */
		ImageView btn_memberGood = (ImageView) msgadd.findViewById(R.id.btn_membergood);
		btn_memberGood.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 隐藏软键盘
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.edit_msg)
						.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

				Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "按讚中");// 秀轉轉
				mHandler.sendMessage(msg1);
				if (IS_DEBUG) {Log.d("ken", "按讚");}
				/* 會員按讚 */
				if (PersonalBean.getInstance().getChtsn() != 0) {

					Olympic olympic = (Olympic) getApplicationContext();
					/* 先產生GAMECODE */
					GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic.getBabyCatchId());
					guestRecordUploadEvent.addCallback(new IEventCallback() {
						@Override
						public void result(Event event, Object result) {
							Olympic olympic = (Olympic) getApplicationContext();
							olympic.setGameCode("");
							if (((GuestRecordUploadBean) result).getResult() == 0000) {
								/* 接著會員按讚 */
								MemberGoodEvent memberGoodEvent = new MemberGoodEvent(TreeActivity.this, canLikeTreeListData.get(spinerselect).getTreeId(), ((GuestRecordUploadBean) result).getGameCode(), PersonalBean.getInstance().getNickname());
								memberGoodEvent.addCallback(new IEventCallback() {

									@Override
									public void result(Event event, Object result) {
										Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
										mHandler.sendMessage(msg1);

										Message msg;
										switch (((MemberGoodBean) result).getResult()) {
										case 9999:
											msg = mHandler.obtainMessage(MSGUPLOAD_ERROR);
											mHandler.sendMessage(msg);
											break;
										case 0000:
											msgadd = null;
											msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
											mHandler.sendMessage(msg);
											/** 送出加油的流水密碼 */
											if (((MemberGoodBean) result).getGiftId() > 0) {
												toMailMessageGoldCode(((MemberGoodBean) result).getGiftNumber());
											}
											Message msg2 = mHandler.obtainMessage(MSG_SHOW, "按讚成功");
											mHandler.sendMessage(msg2);

											/** 臉書按讚 */
											hasMessage = false;
											Message msg3 = mHandler.obtainMessage(FB_LIKE);
											mHandler.sendMessage(msg3);
											/* 查詢選手樹 */
											QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
													canLikeTreeListData.get(spinerselect).getTreeId());
											mGetTreeSingleEvent.addCallback(new IEventCallback() {
												@Override
												public void result(Event event, Object result) {
													treeSingleListData.clear();
													treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
													Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
													mHandler.sendMessage(msg);

												}

												@Override
												public void progress(Event event, int progress, String tmpPath) {
												}
											});
											KenEventManager.getInstance().execute(mGetTreeSingleEvent);
											break;
										}
									}

									@Override
									public void progress(Event event, int progress, String tmpPath) {

									}
								});
								KenEventManager.getInstance().execute(memberGoodEvent);
							} else {
								Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 秀轉轉
								mHandler.sendMessage(msg1);
							}
						}

						@Override
						public void progress(Event event, int progress, String tmpPath) {
						}
					});

					KenEventManager.getInstance().execute(guestRecordUploadEvent);
				}

				else /* 訪客按讚 */
				{
					if (IS_DEBUG) {Log.d("ken", "訪客按讚");}
					Olympic olympic = (Olympic) getApplicationContext();
					/* 先產生GAMECODE */
					GuestRecordUploadEvent guestRecordUploadEvent = new GuestRecordUploadEvent(TreeActivity.this, olympic.getBabyCatchId());
					guestRecordUploadEvent.addCallback(new IEventCallback() {
						@Override
						public void result(Event event, Object result) {
							Olympic olympic = (Olympic) getApplicationContext();
							olympic.setGameCode("");
							if (((GuestRecordUploadBean) result).getResult() == 0000) {

								VisitorGoodEvent VisitorGoodEvent = new VisitorGoodEvent(TreeActivity.this, canLikeTreeListData.get(spinerselect)
										.getTreeId(), ((GuestRecordUploadBean) result).getGameCode(), KenEventManager.getInstance()
										.getGuestname(), KenEventManager.getInstance().getGuestMobile(), 1);
								VisitorGoodEvent.addCallback(new IEventCallback() {

									@Override
									public void result(Event event, Object result) {
										Message msg1 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);// 取消秀轉轉
										mHandler.sendMessage(msg1);

										Message msg;
										switch (((VisitorGoodBean) result).getResult()) {
										case 9999:
											msg = mHandler.obtainMessage(MSG_SHOW, ((VisitorGoodBean) result).getMessage());
											mHandler.sendMessage(msg);
											break;
										case 0000:
											msgadd = null;
											msg = mHandler.obtainMessage(INITLAYOUT2, spinerselect, canLikeTreeListData.get(spinerselect).getTreeId());
											mHandler.sendMessage(msg);
											/** 送出加油的流水密碼 */
											if (((VisitorGoodBean) result).getGiftId() > 0) {
												toMailMessageGoldCode(((VisitorGoodBean) result).getGiftNumber());
											}
											Message msg2 = mHandler.obtainMessage(MSG_SHOW, "按讚成功");
											mHandler.sendMessage(msg2);
											QueryTreeContentEvent mGetTreeSingleEvent = new QueryTreeContentEvent(TreeActivity.this,
													canLikeTreeListData.get(spinerselect).getTreeId());
											mGetTreeSingleEvent.addCallback(new IEventCallback() {
												@Override
												public void result(Event event, Object result) {
													treeSingleListData.clear();
													treeSingleListData.addAll((Collection<? extends TreeSingleBean>) result);
													Message msg = mHandler.obtainMessage(TREESINGLE_ADAPTER_NOTIFY_DATA);
													mHandler.sendMessage(msg);

													/** 臉書按讚 */
													hasMessage = false;
													Message msg3 = mHandler.obtainMessage(FB_LIKE);
													mHandler.sendMessage(msg3);
												}

												@Override
												public void progress(Event event, int progress, String tmpPath) {
												}
											});
											KenEventManager.getInstance().execute(mGetTreeSingleEvent);
											break;
										}
									}

									@Override
									public void progress(Event event, int progress, String tmpPath) {

									}
								});
								KenEventManager.getInstance().execute(VisitorGoodEvent);

							}

						}

						@Override
						public void progress(Event event, int progress, String tmpPath) {
						}
					});

					KenEventManager.getInstance().execute(guestRecordUploadEvent);
				}

			}
		});

		/* 返回按鈕 */
		ImageView btn_MsgaddBack = (ImageView) msgadd.findViewById(R.id.msgadd_back);
		btn_MsgaddBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 隐藏软键盘
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.edit_msg)
						.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

				// cleanerLayout();
				Message msg = mHandler.obtainMessage(SHOW_ALERTDIALOG_MSGADDBACK);
				mHandler.sendMessage(msg);

			}
		});

	}

	public String getDateTime() {
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
		Date date = new Date();
		String strDate = sdFormat.format(date);
		// System.out.println(strDate);
		return strDate;
	}

	private void cleanerLayout() {

		if (layout1a_bmpDrawImg != null && !layout1a_bmpDrawImg.getBitmap().isRecycled()) {
			((FrameLayout) layout1_a).getBackground().setCallback(null);
			((FrameLayout) layout1_a).setBackgroundDrawable(null);
			layout1a_bmpDrawImg.getBitmap().recycle();
			layout1a_bmpDrawImg = null;
		}

		if (loginInfoBgbitmap != null && !loginInfoBgbitmap.isRecycled()) {
			loginInfoBgbitmap.recycle();
			loginInfoBgbitmap = null;
		}

		if (getGiftPage != null) {
			getGiftPage.setVisibility(View.GONE);
			getGiftPage.removeAllViews();
			getGiftPage = null;
		}

		if (treeSinglMsgPop != null) {
			treeSinglMsgPop.setVisibility(View.GONE);
			treeSinglMsgPop.removeAllViews();
			treeSinglMsgPop = null;
		}

		if (setting != null) {
			setting.removeAllViews();
			setting = null;
		}

		if (layout1_b != null) {
			((RelativeLayout) layout1_b).getBackground().setCallback(null);
			((RelativeLayout) layout1_b).setBackgroundDrawable(null);
			((RelativeLayout) layout1_b).removeAllViews();
			layout1_b = null;
			// ((FrameLayout)layout1_b).getBackground().setCallback(null);
		}
		if (null != layout1b_bmpDrawImg && !layout1b_bmpDrawImg.getBitmap().isRecycled()) {
			layout1b_bmpDrawImg.getBitmap().recycle();
			layout1b_bmpDrawImg = null;
		}

		if (msgadd != null) {
			msgadd.removeAllViews();
			msgadd = null;
		}

		if (multiLoginPage != null) {
			multiLoginPage.removeAllViews();
			multiLoginPage = null;
		}

		if (loginPage != null) {
			loginPage.removeAllViews();
			loginPage = null;
		}

		if (guestLogin != null) {
			guestLogin.removeAllViews();
			guestLogin = null;
		}
		
		if (bySharebabyPage != null) {
			bySharebabyPage.removeAllViews();
			bySharebabyPage = null;
		}
		  
		if (bySharebabyStep1Page != null) {
			bySharebabyStep1Page.removeAllViews();
			bySharebabyStep1Page = null;
		} 

		if (bySharebabyStep2Page != null) {
			bySharebabyStep2Page.removeAllViews();
			bySharebabyStep2Page = null;
		}
		if (byGetbabyPage != null) {
			byGetbabyPage.removeAllViews();
			byGetbabyPage = null;
		}
		
		if (member_MainLayout != null) {
			member_MainLayout.getBackground().setCallback(null);
			member_MainLayout.setBackgroundDrawable(null);
			member_MainLayout.removeAllViews();
			member_MainLayout = null;
			// mMemberContentListView.removeAllViews();
			if (mPersonlContentListView != null) {
				// mPersonlContentListView.removeAllViews();
				mPersonlContentListView = null;
			}

			member_BabyList = null;
			member_WebView = null;
			member_Listview = null;
		}

		if (null != memberMainLayout_bmpDrawImg && !memberMainLayout_bmpDrawImg.getBitmap().isRecycled()) {
			memberMainLayout_bmpDrawImg.getBitmap().recycle();
			memberMainLayout_bmpDrawImg = null;
		}

		if (morepageBgbitmap != null && !morepageBgbitmap.getBitmap().isRecycled()) {
			morepageBgbitmap.getBitmap().recycle();
			morepageBgbitmap = null;
		}

		if (personal_MainLayout != null) {
			personal_MainLayout.removeAllViews();
			personal_MainLayout = null;
			// mMemberContentListView.removeAllViews();
			if (mPersonlContentListView != null) {
				// mPersonlContentListView.removeAllViews();
				mPersonlContentListView = null;
			}
		}

		if (more_Page != null) {
			more_Page.getBackground().setCallback(null);
			more_Page.setBackgroundDrawable(null);
			more_Page.removeAllViews();
			more_Page = null;
			// mMemberContentListView.removeAllViews();
			mPersonCouponListView = null;
			if (mPersonCouponListView != null) {
				// mPersonlContentListView.removeAllViews();
				mPersonCouponListView = null;
			}
		}

		if (null != morepage_bmpDrawImg && !morepage_bmpDrawImg.getBitmap().isRecycled()) {
			morepage_bmpDrawImg.getBitmap().recycle();
			morepage_bmpDrawImg = null;
		}

		if (null != personal_bmpDrawImg && !personal_bmpDrawImg.getBitmap().isRecycled()) {
			personal_bmpDrawImg.getBitmap().recycle();
			personal_bmpDrawImg = null;
		}

		if (mSingleTreeListView != null) {
			// mPersonlContentListView.removeAllViews();
			mMemberTreeAdapter = null;
			mSingleTreeListView = null;
		}

//		treeSingleListData.clear();// 留言ArrayList
//		memberContentData.clear();// 會員留言ArrayList
//		quertPersonCouponData.clear();// 會員個人優惠果實ArrayList
//		System.gc();
	}

	/* 載入收集冊 */
	private void intoMemberLayout() {
		// Cliff add
		((Olympic) this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER;
		//

		QueryPersonalBabyEvent mQueryPersonalBabyEvent = new QueryPersonalBabyEvent(TreeActivity.this);
		mQueryPersonalBabyEvent.addCallback(new IEventCallback() {

			@Override
			public void result(Event event, Object result) {
				queryPersonBabyData.clear();
				queryPersonBabyData.addAll((Collection<? extends QueryPersonalBabyBean>) result);

				// 寶寶圖置換
				for (int i = 0; i < sportBabyListData.size(); i++) {
					for (int j = 0; j < queryPersonBabyData.size(); j++) {
						if (sportBabyListData.get(i).getBabyId() == queryPersonBabyData.get(j).getBabyId()) {
							sportBabyListData.get(i).setBabyNum(queryPersonBabyData.get(j).getBabyNum());
							String temp = sportBabyListData.get(i).getShowImg();
							temp = temp.replace("2.png", "1.png");
							temp = temp.substring(0, 9);
							if (sportBabyListData.get(i).getBabyNum() >0) {
								temp = temp + "1";
							}else{
								temp = temp + "2";
							}
							sportBabyListData.get(i).setShowImg(temp);
							temp = null;
						}
					}
				}
				Message msg = mHandler.obtainMessage(BABYLIST_ADAPTER_NOTIFY_DATA);
				mHandler.sendMessage(msg);

			}

			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(mQueryPersonalBabyEvent);
		
		QueryPersonCouponEvent queryPersonCouponEvent = new QueryPersonCouponEvent(TreeActivity.this);
		queryPersonCouponEvent.addCallback(new IEventCallback() {
			@Override
			public void result(Event event, Object result) {
				if (((List<QueryPersonCouponBean>) result).size() > 0) {
					quertPersonCouponData.clear();
					quertPersonCouponData.addAll((List<QueryPersonCouponBean>) result);
					Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 0, -1);
					mHandler.sendMessage(msg);
				} else if (((List<QueryPersonCouponBean>) result).size() == 0) {
					// TODO 切換尚未收集到優惠果實
					Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 2, -1);
					mHandler.sendMessage(msg);
				}
			}
			@Override
			public void progress(Event event, int progress, String tmpPath) {
			}
		});
		KenEventManager.getInstance().execute(queryPersonCouponEvent);

		member_MainLayout = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.memberlayout, null);
		memberMainLayout_bmpDrawImg = new BitmapDrawable(Helper.readBitMapforBG(TreeActivity.this, R.drawable.bg1_04_1));
		member_MainLayout.setBackgroundDrawable(memberMainLayout_bmpDrawImg);

		setLayoutView(member_MainLayout);
		addToolbar(TreeActivity.this, 3);
		initMemberLayout(1);
		// 收集冊加油寶寶
		ImageView btn_babyList = (ImageView) member_MainLayout.findViewById(R.id.btn_babylist);
		btn_babyList.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					cleanerLayout();
					intoMemberLayout();
				}
			}
		});
		// 收集冊優惠果實
		ImageView btn_ListView = (ImageView) member_MainLayout.findViewById(R.id.btn_listview);
		btn_ListView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					initMemberLayout(2);
					QueryPersonCouponEvent queryPersonCouponEvent = new QueryPersonCouponEvent(TreeActivity.this);
					queryPersonCouponEvent.addCallback(new IEventCallback() {
						@Override
						public void result(Event event, Object result) {
							if (((List<QueryPersonCouponBean>) result).size() > 0) {
								quertPersonCouponData.clear();
								quertPersonCouponData.addAll((List<QueryPersonCouponBean>) result);
								Message msg = mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA, 0, -1);
								mHandler.sendMessage(msg);
							} else if (((List<QueryPersonCouponBean>) result).size() == 0) {
								// TODO 切換尚未收集到優惠果實
								// Message msg =
								// mHandler.obtainMessage(PERSONCOUPON_ADAPTER_NOTIFY_DATA,
								// 2, -1);
								// mHandler.sendMessage(msg);
							}
						}

						@Override
						public void progress(Event event, int progress, String tmpPath) {
						}
					});
					KenEventManager.getInstance().execute(queryPersonCouponEvent);
				}
			}
		});
		// 收集冊優惠好禮
		ImageView btn_webView = (ImageView) member_MainLayout.findViewById(R.id.btn_webview);
		btn_webView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				/* popraw開啟時無法點擊 */
				if (!giftMsgPopisOpen && !personalMsgPopisOpen && !sportsmanMsgPopisOpen) {
					initMemberLayout(3);
				}
			}
		});
	}

	/** 訪客登入頁 */
	private void initGuestLogin(final Message message, final int layoutId) {
		LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
		guestLogin = (RelativeLayout) inflater.inflate(R.layout.by_guest_login_page, null);
		setLayoutView(guestLogin);
		// addContentView(guestLogin, new LayoutParams(LayoutParams.FILL_PARENT,
		// LayoutParams.FILL_PARENT));

		/* 登入按鈕 */
		ImageView btn_Login = (ImageView) findViewById(R.id.guest_login);
		btn_Login.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// =============
				EditText guestNickname = (EditText) findViewById(R.id.guestlogin_nickname);
				EditText guestPhonenum = (EditText) findViewById(R.id.guestlogin_phonenum);
				/* 判斷欄位是否有未填 */
				if ((guestNickname.getText().toString() != null && !(guestNickname.getText().toString().trim()).equals(""))
						&& (guestPhonenum.getText().toString() != null && !(guestPhonenum.getText().toString().trim()).equals(""))
						&& ((guestPhonenum.getText().toString().trim()).substring(0, 2)).equals("09")) {
					// 隐藏软键盘
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
							(IBinder) findViewById(R.id.guestlogin_nickname).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

					/* 儲存暱稱 */
					KenEventManager.getInstance().setGuestname(guestNickname.getText().toString());
					PersonalBean.getInstance().setGuestname(guestNickname.getText().toString());
					/* 儲存門號 */
					KenEventManager.getInstance().setGuestMobile(guestPhonenum.getText().toString());
					PersonalBean.getInstance().setGuestmobile(guestPhonenum.getText().toString());

					if (layoutId == 9) {
						Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_SHOW, "載入留言頁中...");
						mHandler.sendMessage(message);
						VisitorCanLikeEvent canLikeEvent = new VisitorCanLikeEvent(TreeActivity.this);
						canLikeEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								Message message = mHandler.obtainMessage(TreeActivity.PROGRESSDIALOD_CANCEL);
								mHandler.sendMessage(message);
								if (!(result instanceof String && ((String) result).equals("ERROR"))) {
									 if (((ArrayList<TreeAllBean>) result).size() == 0){
											// 切回照集
											Intent it = new Intent();
											it.setClass(TreeActivity.this, ARExampleActivity.class);
											startActivityForResult(it, GETBABY_RESULT);
											Message msg = mHandler.obtainMessage(SHOW_TOAST,"您已為所有選手加油過了唷！歡迎您一小時候再來為選手照集加油！");
											mHandler.sendMessage(msg);
									} else{
										canLikeTreeListData.clear();
										canLikeTreeListData.addAll((Collection<? extends TreeAllBean>) result);
										Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 9, 0, PersonalBean.getInstance().getGuestname());
										mHandler.sendMessage(msg);	
									}
								} else {
									// 切回照集
									Intent it = new Intent();
									it.setClass(TreeActivity.this, ARExampleActivity.class);
									startActivityForResult(it, GETBABY_RESULT);
									Message msg = mHandler.obtainMessage(SHOW_TOAST,"網路異常返回照集");
									mHandler.sendMessage(msg);
								}
							}
							@Override
							public void progress(Event event, int progress, String tmpPath) {
							}
						});
						KenEventManager.getInstance().execute(canLikeEvent);

					} else if (layoutId == 5) {
						Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 5, 0);
						mHandler.sendMessage(msg);
					}

				} else {
					Toast.makeText(getApplicationContext(), "門號格式錯誤或暱稱電話未輸入", Toast.LENGTH_SHORT).show();
				}

				// ===============
			}
		});

		/* 返回按鈕 */
		ImageView btn_back = (ImageView) findViewById(R.id.guestlogpage_back);
		btn_back.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				// 隐藏软键盘
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
						(IBinder) findViewById(R.id.guestlogin_nickname).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

				LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
				multiLoginPage = (RelativeLayout) inflater.inflate(R.layout.by_multi_login_page, null);
				setLayoutView(multiLoginPage);

				/* 返回按鈕 */
				ImageView btn_back = (ImageView) findViewById(R.id.multilogpage_back);
				btn_back.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// 隐藏软键盘
						((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
								(IBinder) findViewById(R.id.multilogin_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
						cleanerLayout();
						setBackgroundLayout();
					}
				});

				/* 加入會員按鈕 */
				ImageView btn_addMember = (ImageView) findViewById(R.id.multilogpage_addmember);
				btn_addMember.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
					}
				});
				/* 忘記密碼按鈕 */
				ImageView btn_forGetpass = (ImageView) findViewById(R.id.multilogpage_forgetpss);
				btn_forGetpass.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
					}
				});
				/* 登入按鈕 */
				ImageView btn_Login = (ImageView) findViewById(R.id.multilogpage_login);
				btn_Login.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// =============
						EditText account = (EditText) findViewById(R.id.multilogin_account);
						EditText password = (EditText) findViewById(R.id.multilogin_password);

						if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
						if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
						/* 判斷欄位是否有未填 */
						if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
								&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
							// 隐藏软键盘
							((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
									(IBinder) findViewById(R.id.multilogin_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
							/* 轉轉 */
							Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
							mHandler.sendMessage(msg);

							PersonalBean.getInstance().setAccount(account.getText().toString());
							PersonalBean.getInstance().setPassword(password.getText().toString());
							LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
							loginEvent.addCallback(new IEventCallback() {
								@Override
								public void result(Event event, Object result) {
									/* 取消轉轉 */
									Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
									mHandler.sendMessage(msg2);

									if (((PersonalBean) result).getChtsn() == 0 || ((PersonalBean) result).getUserType() == -1) {
										Message msg = mHandler.obtainMessage(MSG_SHOW, ((PersonalBean) result).getLoginMessage());
										mHandler.sendMessage(msg);
										if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
									} else {
										/* 儲存sn */
										KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
										/* 儲存帳號 */
										KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
										/* 儲存nickname */
										KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
										/* 儲存usertype */
										KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
										if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}

										/* 推播更新 */
										UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null,
												((Olympic) getApplicationContext()).getRegistrationID());
										updPushTokenEvent.addCallback(new IEventCallback() {

											@Override
											public void result(Event event, Object result) {
												if (result instanceof UpdPushTokenBean) {
													if (((UpdPushTokenBean) result).getResult() == 0000) {
														if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
														// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
													}
												} else if (result == null) {
													if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
												}

											}

											@Override
											public void progress(Event event, int progress, String tmpPath) {
											}
										});
										KenEventManager.getInstance().execute(updPushTokenEvent);

										// initMsgAddPage(PersonalBean.getInstance().getNickname());
										// Message msg =
										// mHandler.obtainMessage(SET_LAYOUTVIEW,
										// 9, 0,
										// PersonalBean.getInstance().getNickname());
										mHandler.sendMessage(message);
									}

								}

								@Override
								public void progress(Event event, int progress, String tmpPath) {

								}
							});

							KenEventManager.getInstance().execute(loginEvent);
						} else {
							Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
						}

						// ===============
					}
				});

				/* 訪客登入 */
				ImageView btn_guestLogin = (ImageView) findViewById(R.id.multilogpage_guestlogin);
				btn_guestLogin.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						initGuestLogin(message, layoutId);
					}
				});
			}
		});

	}

	// ===========facebook========

	// post message on wall...
	// public void postMessage() {
	//
	// if (facebookConnector.getFacebook().isSessionValid()) {
	// postMessageInThread();
	// } else {
	// SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {
	//
	// @Override
	// public void onAuthSucceed() {
	// postMessageInThread();
	// }
	//
	// @Override
	// public void onAuthFail(String error) {
	//
	// }
	// };
	// SessionEvents.addAuthListener(listener);
	// facebookConnector.login();
	// }
	// }

	// post message thread...
	private void postMessageInThread(final String spName, final String fbmsg) {
		Thread t = new Thread() {
			public void run() {

				try {
					String wallName = "" ;
					if (KenEventManager.getInstance().getCHTsn()!=0) {
						wallName = KenEventManager.getInstance().getNICKName();
					}else{
						wallName = KenEventManager.getInstance().getGuestname();
					}
					if (hasMessage) { // has message for contestant...留言
						String msg = "GO!!"; // for test only...
						String link = TreeActivity.this.getResources().getString(R.string.game_link);
						String name = wallName + TreeActivity.this.getResources().getString(R.string.has_msg_name_seg1)
								+ spName + // contestant
											// name...
								TreeActivity.this.getResources().getString(R.string.has_msg_name_seg2) + fbmsg;// 留言內容
						String description = TreeActivity.this.getResources().getString(R.string.has_msg_description);
						/*-----------------------------------------------------------------------------------*/
						facebookConnector.postMessageOnWall(msg, link, name, description);
						/*-----------------------------------------------------------------------------------*/
					} else { // has no message for contestant...按讚
						String msg = "GO!!"; // for test only...
						String link = TreeActivity.this.getResources().getString(R.string.game_link);
						String name = wallName + TreeActivity.this.getResources().getString(R.string.no_msg_name_seg1)
								+ spName + // contestant
											// name...
								TreeActivity.this.getResources().getString(R.string.no_msg_name_seg2);
						String description = TreeActivity.this.getResources().getString(R.string.no_msg_description);
						/*-----------------------------------------------------------------------------------*/
						facebookConnector.postMessageOnWall(msg, link, name, description);
						/*-----------------------------------------------------------------------------------*/
					}

					// hasMessage = !hasMessage;

					// just notify that message was sent...
					// mFacebookHandler.post(mUpdateFacebookNotification);
				} catch (Exception ex) {
					// Log.e(TAG, "Error sending msg",ex);
				}
			}
		};
		t.start();
	}

	// private final int MESSAGE_ID_SETINFO = 1000;

	// private final Handler mFacebookHandler = new Handler() {
	// public void handleMessage(Message msg) {
	// switch (msg.what){
	// case MESSAGE_ID_SETINFO:
	// show_request.setText("User : " + mUserName + "\n" +
	// "First Name : " + mUserfName + "\n" +
	// "Last Name : " + mUserlName + "\n" +
	// "User ID : " + mUserID);
	// break;
	// default:
	// break;
	// }
	// }
	// };

	// final Runnable mUpdateFacebookNotification = new Runnable() {
	// public void run() {
	// Toast.makeText(getBaseContext(), "Facebook updated !",
	// Toast.LENGTH_LONG).show();
	// }
	// };

	// @Override
	// protected void onActivityResult(int requestCode, int resultCode, Intent
	// data) {
	// /*-----------------------------------------------------------------------------------*/
	// this.facebookConnector.getFacebook().authorizeCallback(requestCode,
	// resultCode, data);
	// /*-----------------------------------------------------------------------------------*/
	// }

	// get login user info
	public void requestUserInfo(final String spName, final String fbmsg) {

		if (facebookConnector.getFacebook().isSessionValid()) {
			requestUserInThread(spName, fbmsg);
		} else {
			SessionEvents.AuthListener listener = new SessionEvents.AuthListener() {

				@Override
				public void onAuthSucceed() {
					if (spName.equals(NOfbAgain)) {
						requestUserInThread(spName, fbmsg);
					}
				}

				@Override
				public void onAuthFail(String error) {

				}
			};
			SessionEvents.addAuthListener(listener);
			facebookConnector.login();
		}
	}

	private void requestUserInThread(final String spName, final String fbmsg) {
		Thread t = new Thread() {
			public void run() {

				try {
					//
					JSONObject me = null;
					me = facebookConnector.requestUserInfo();

					if (me != null) {
						// Log.i(TAG, "me = " + me);
						//
						mUserName = me.getString("name");
						// mUserfName = me.getString("first_name");
						// mUserlName = me.getString("last_name");
						// mUserID = me.getString("id");
						// notify ui to show...
						// mFacebookHandler.sendEmptyMessage(MESSAGE_ID_SETINFO);

						postMessageInThread(spName, fbmsg);
					}

				} catch (Exception ex) {
					// Log.e(TAG, "Error sending msg",ex);
				}
			}
		};
		t.start();
	}
	
	// ===========設定頁==============
	public void setting(View view) {
		if (IS_DEBUG) {Log.d("ken", "setting");}
		setting = (RelativeLayout) LayoutInflater.from(TreeActivity.this).inflate(R.layout.more_setting, null);
		setLayoutView(setting);
		addToolbar(TreeActivity.this, 4);
		/* 非會員不顯示推播 */
		if (KenEventManager.getInstance().getCHTsn() == 0) {
			View pushtoken = findViewById(R.id.push_token);
			pushtoken.setVisibility(View.GONE);
		}
	
		/* 登入登出按鈕 */
		TextView logstate = (TextView) findViewById(R.id.setting_logstate);
		if (KenEventManager.getInstance().getCHTsn() != 0 || !(KenEventManager.getInstance().getGuestname().equals(""))) {
			logstate.setText("登出");
			/* 顯示登入帳號 */
			if (KenEventManager.getInstance().getAccount().equals("null")) {
				Message msg = new Message();
				msg.what = SETTEXT_FOR_TEXTVIEW;
				msg.arg1 = R.id.setting_username;
				msg.obj = KenEventManager.getInstance().getGuestname();
				mHandler.sendMessage(msg);
			} else {
				Message msg = new Message();
				msg.what = SETTEXT_FOR_TEXTVIEW;
				msg.arg1 = R.id.setting_username;
				msg.obj = KenEventManager.getInstance().getAccount();
				mHandler.sendMessage(msg);
			}
	
		} else if (KenEventManager.getInstance().getCHTsn() == 0 && KenEventManager.getInstance().getGuestname().equals("")) {
			logstate.setText("登入");
		}
		/* fbName */
		Message msg = new Message();
		msg.what = SETTEXT_FOR_TEXTVIEW;
		msg.arg1 = R.id.fb_name;
		msg.obj = mUserName;
		mHandler.sendMessage(msg);
		TextView textView = (TextView) findViewById(R.id.fb_name_logout);
		textView.setText("已登出");
		if (!mUserName.equals("")) {
			textView.setTextColor(Color.BLACK);
			textView.setText("登出");
		}
		/* 推播開關 */
		final ToggleButton pushToken = (ToggleButton) findViewById(R.id.btn_pushtoken);
		if (((Olympic) getApplicationContext()).prefs.getBoolean(Olympic.PUSH_ENABLED_PREF_KEY, false)) {
			pushToken.setChecked(true);
		} else {
			pushToken.setChecked(false);
		}
	
		pushToken.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() {
	
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
	
				if (isChecked) {
					/* 開啟推播 */
					Olympic olympic = (Olympic) getApplicationContext();
					olympic.enablePush(true);
	
				} else {
					Olympic olympic = (Olympic) getApplicationContext();
					olympic.enablePush(false);
				}
			}
		});
	}

	/* 登入背景說明頁 */
	private void showLoginInfo() {
		if (loginInfoPage != null) {
			loginInfoPage.setVisibility(View.GONE);
			loginInfoPage.removeAllViews();
			loginInfoPage = null;
			loginInfoPageisOpen = false;
			if (loginInfoBgbitmap != null && !loginInfoBgbitmap.isRecycled()) {
				loginInfoBgbitmap.recycle();
				loginInfoBgbitmap = null;
			}
		}
		LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
		loginInfoPage = (RelativeLayout) inflater.inflate(R.layout.by_login_info, null);
		addContentView(loginInfoPage, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		loginInfoPageisOpen = true;
		ImageView bg = (ImageView) findViewById(R.id.by_login_info_bg);
		loginInfoBgbitmap = Helper.getLocalBitmap(TreeActivity.this, R.drawable.popo02_05);
		bg.setImageBitmap(loginInfoBgbitmap);
		bg.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
			}
		});
		ImageView cancel = (ImageView) loginInfoPage.findViewById(R.id.by_login_info_cencel);
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				loginInfoPage.setVisibility(View.GONE);
				loginInfoPage.removeAllViews();
				loginInfoPage = null;
				loginInfoPageisOpen = false;
				if (loginInfoBgbitmap != null && !loginInfoBgbitmap.isRecycled()) {
					loginInfoBgbitmap.recycle();
					loginInfoBgbitmap = null;
				}
				// Cliff add
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL_LOGIN;

			}
		});
	}
	
	// ================更多=================
	public void eventInfos(View view) {
		infosView.loadUrl(SEVER_API+"/olympic/event_infos");
		// infosView.setWebViewClient(new WebViewClient());
		infosView.requestFocus();
		// infosViewPanel.addView(infosView);
		setLayoutView(infosViewPanel);
		addToolbar(TreeActivity.this, 4);
	}

	public void infos(View view) {
		infosView.loadUrl(SEVER_API+"/olympic/infos");
		// infosView.setWebViewClient(new WebViewClient());
		infosView.requestFocus();
		// infosViewPanel.addView(infosView);
		setLayoutView(infosViewPanel);
		addToolbar(TreeActivity.this, 4);
	}

	public void collabs(View view) {
		infosView.loadUrl(SEVER_API+"/olympic/collabs");
		// infosView.setWebViewClient(new WebViewClient());
		infosView.requestFocus();
		// infosViewPanel.addView(infosView);
		setLayoutView(infosViewPanel);
		addToolbar(TreeActivity.this, 4);
	}

	public void apps(View view) {
		infosView.loadUrl(SEVER_API+"/olympic/apps");
		// infosView.setWebViewClient(new WebViewClient());
		infosView.requestFocus();
		// infosViewPanel.addView(infosView);
		setLayoutView(infosViewPanel);
		addToolbar(TreeActivity.this, 4);
	}

	public void settingLogInOut(View view) {
		if (IS_DEBUG) {Log.d("ken", "setting");}
		TextView logstate = (TextView) findViewById(R.id.setting_logstate);
		if (IS_DEBUG) {Log.d("ken", "" + KenEventManager.getInstance().getCHTsn() + " " + KenEventManager.getInstance().getGuestname());}
		if (KenEventManager.getInstance().getCHTsn() != 0 || !(KenEventManager.getInstance().getGuestname().equals(""))) {

			KenEventManager.getInstance().setCHTsn(0);
			KenEventManager.getInstance().setAccount("null");
			KenEventManager.getInstance().setGuestname("");
			PersonalBean.getInstance().setChtsn(0);
			PersonalBean.getInstance().setAccount("null");
			PersonalBean.getInstance().setGuestname("");
			/* 推播更新 */
			UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null, ((Olympic) getApplicationContext()).getRegistrationID());
			updPushTokenEvent.addCallback(new IEventCallback() {

				@Override
				public void result(Event event, Object result) {
					if (result instanceof UpdPushTokenBean) {
						if (((UpdPushTokenBean) result).getResult() == 0000) {
							if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
						}
					} else if (result == null) {
						if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
					}
				}

				@Override
				public void progress(Event event, int progress, String tmpPath) {
				}
			});
			KenEventManager.getInstance().execute(updPushTokenEvent);

			/* 顯示登出頁 */
			setting(null);

		} else if (KenEventManager.getInstance().getCHTsn() == 0 && KenEventManager.getInstance().getGuestname().equals("")) {

			// // Cliff add
			// ((Olympic)TreeActivity.this.getApplication()).mPageIndex =
			// Olympic.PageIndex.MORE_LOGIN;
			// //

			LayoutInflater inflater = LayoutInflater.from(TreeActivity.this);
			View login = inflater.inflate(R.layout.by_multi_login_page, null);
			setLayoutView(login);
			/* 登入背景說明頁 */
			showLoginInfo();
			/* 返回按鈕 */
			ImageView btn_back = (ImageView) findViewById(R.id.multilogpage_back);
			btn_back.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (!loginInfoPageisOpen) {
						// 隐藏软键盘
						((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
								(IBinder) findViewById(R.id.multilogin_password).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
						cleanerLayout();
						setBackgroundLayout();
						((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
					}
				}
			});

			/* 加入會員按鈕 */
			ImageView btn_addMember = (ImageView) findViewById(R.id.multilogpage_addmember);
			btn_addMember.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Helper.browerOpenUrl(TreeActivity.this, URL_ADDMEMBER);
				}
			});
			/* 忘記密碼按鈕 */
			ImageView btn_forGetpass = (ImageView) findViewById(R.id.multilogpage_forgetpss);
			btn_forGetpass.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Helper.browerOpenUrl(TreeActivity.this, URL_FORGETPASS);
				}
			});
			/* 登入按鈕 */
			ImageView btn_Login = (ImageView) findViewById(R.id.multilogpage_login);
			btn_Login.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// =============
					EditText account = (EditText) findViewById(R.id.multilogin_account);
					EditText password = (EditText) findViewById(R.id.multilogin_password);

					if (IS_DEBUG) {Log.d("ken", "account" + account.getText().toString());}
					if (IS_DEBUG) {Log.d("ken", "password" + password.getText().toString());}
					/* 判斷欄位是否有未填 */
					if ((account.getText().toString() != null && !(account.getText().toString().trim()).equals(""))
							&& (password.getText().toString() != null && !(password.getText().toString().trim()).equals(""))) {
						// 隐藏软键盘
						((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(password.getWindowToken(),
								InputMethodManager.HIDE_NOT_ALWAYS);
						/* 轉轉 */
						Message msg = mHandler.obtainMessage(PROGRESSDIALOD_SHOW, "登入中...");
						mHandler.sendMessage(msg);

						PersonalBean.getInstance().setAccount(account.getText().toString());
						PersonalBean.getInstance().setPassword(password.getText().toString());
						LoginEvent loginEvent = new LoginEvent(TreeActivity.this);
						loginEvent.addCallback(new IEventCallback() {
							@Override
							public void result(Event event, Object result) {
								/* 取消轉轉 */
								Message msg2 = mHandler.obtainMessage(PROGRESSDIALOD_CANCEL);
								mHandler.sendMessage(msg2);
								// 判斷是否登入成功
								if (((PersonalBean) result).getChtsn() == 0) {
									Message msg = mHandler.obtainMessage(MSG_SHOW, ((PersonalBean) result).getLoginMessage());
									mHandler.sendMessage(msg);
									if (IS_DEBUG) {Log.d("ken", "登入失敗 可能網路可能帳密錯誤");}
								} else {
									/* 儲存sn */
									KenEventManager.getInstance().setCHTsn(((PersonalBean) result).getChtsn());
									/* 儲存帳號 */
									KenEventManager.getInstance().setAccount(((PersonalBean) result).getAccount());
									/* 儲存nickname */
									KenEventManager.getInstance().setNICKName(((PersonalBean) result).getNickname());
									/* 儲存usertype */
									KenEventManager.getInstance().setUserType(((PersonalBean) result).getUserType());
									if (IS_DEBUG) {Log.d("ken", "UserType" + ((PersonalBean) result).getUserType());}

									/* 推播更新 */
									UpdPushTokenEvent updPushTokenEvent = new UpdPushTokenEvent(null, ((Olympic) getApplicationContext())
											.getRegistrationID());
									updPushTokenEvent.addCallback(new IEventCallback() {

										@Override
										public void result(Event event, Object result) {
											if (result instanceof UpdPushTokenBean) {
												if (((UpdPushTokenBean) result).getResult() == 0000) {
													if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟成功");}
													// C2DMReceiver.this.getApp(context).setRegistrationID(((UpdPushTokenEvent)event).getRegid());
												}
											} else if (result == null) {
												if (IS_DEBUG) {Log.d("ken", "updPushTokenEvent開啟失敗");}
											}

										}

										@Override
										public void progress(Event event, int progress, String tmpPath) {
										}
									});
									KenEventManager.getInstance().execute(updPushTokenEvent);

									/* 顯示更多頁面 */
									Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 5, 0);
									mHandler.sendMessage(msg);
								}

							}

							@Override
							public void progress(Event event, int progress, String tmpPath) {

							}
						});

						KenEventManager.getInstance().execute(loginEvent);
					} else {
						Toast.makeText(getApplicationContext(), "帳號或密碼未輸入", Toast.LENGTH_SHORT).show();
					}
					// ===============
				}
			});

			/* 訪客登入 */
			ImageView btn_guestLogin = (ImageView) findViewById(R.id.multilogpage_guestlogin);
			btn_guestLogin.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Message msg = mHandler.obtainMessage(SET_LAYOUTVIEW, 5, 0);
					initGuestLogin(msg, 5);
				}
			});

			logstate.setText("登入");
		}
	}

	public void fbLogOut(View view) {
		facebookConnector.logout();
		mUserName = "";
		Message msg = new Message();
		msg.what = SETTEXT_FOR_TEXTVIEW;
		msg.arg1 = R.id.fb_name;
		msg.obj = "";
		mHandler.sendMessage(msg);
		TextView textView = (TextView) findViewById(R.id.fb_name_logout);
		textView.setTextColor(Color.GRAY);
		textView.setText("已登出");
	}

	private void toMailMessageGoldCode(String goldcode) {

		// Cliff add
		((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE_CONTESTANY_GIFT1;
		//

		Olympic olympic = (Olympic) getApplicationContext();
		olympic.setGiftPageGoldcode(goldcode);
		Intent it = new Intent();
		it.setClass(TreeActivity.this, MessageGiftActivity.class);
		startActivity(it);
	}

	// Cliff Modified...
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK) {

			if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.TREE_CONTESTANY_LOGIN) {

				gotoTabTree(); // back to Tree
				//
				loginPage = null;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.TREE_CONTESTANY_GIFT0) {
				//
				getGiftPage.setVisibility(View.GONE);
				getGiftPage.removeAllViews();
				getGiftPage = null;
				giftMsgPopisOpen = false;
				personalMsgPopisOpen = false;
				sportsmanMsgPopisOpen = false;
				// back to TREE_CONTESTANY
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE_CONTESTANY;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.PERSONAL_LOGIN) {
				//
				cleanerLayout();
				setBackgroundLayout();
				loginPage = null;
				// back to Tree
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.PERSONAL_GIFT) {
				//
				if (getGiftPage != null) {
					getGiftPage.setVisibility(View.GONE);
					getGiftPage.removeAllViews();
					getGiftPage = null;
					giftMsgPopisOpen = false;
					personalMsgPopisOpen = false;
					sportsmanMsgPopisOpen = false;
				}
				// Back to PERSONAL
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.PERSONAL;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.MEMBER_LOGIN) {
				//
				cleanerLayout();
				setBackgroundLayout();
				loginPage = null;
				// back to Tree
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;
				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.MEMBER_GIFT) {
				//
				if (getGiftPage != null) {
					getGiftPage.setVisibility(View.GONE);
					getGiftPage.removeAllViews();
					getGiftPage = null;
					giftMsgPopisOpen = false;
					personalMsgPopisOpen = false;
					sportsmanMsgPopisOpen = false;
				}
				// Back to MEMBER_PAGE1
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.MEMBER_PAGE1;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.MORE_LOGIN) {
				//
				cleanerLayout();
				setBackgroundLayout();
				// back to Tree
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.AR_LOGIN) {
				//
				cleanerLayout();
				setBackgroundLayout();
				// back to Tree
				((Olympic) TreeActivity.this.getApplication()).mPageIndex = Olympic.PageIndex.TREE;

				return true;
			} else if (((Olympic) TreeActivity.this.getApplication()).mPageIndex == Olympic.PageIndex.AR_MESSAGE) {
				// not implement...

				return false;
			}

		}

		return super.onKeyDown(keyCode, event);
	}

	private void toOpenGiftUrl(final int position) {
		/* 外連兌獎辦法 */

		ImageView getGiftUrl = (ImageView) findViewById(R.id.getgift_url);
		getGiftUrl.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				String sn = String.valueOf(KenEventManager.getInstance().getCHTsn());
				String giftid;
				try {
					giftid = String.valueOf(quertPersonCouponDataOfKind.get(position).getGiftId());
				} catch (Exception e) {
					quertPersonCouponDataOfKind.clear();
					quertPersonCouponDataOfKind.addAll(quertPersonCouponData);
					giftid = String.valueOf(quertPersonCouponDataOfKind.get(position).getGiftId());
				}
				
				String check = KenEventManager.getInstance().genCheckCode(sn + "1");

				if (quertPersonCouponDataOfKind.get(position).getGiftCode() == 1) {
					String url = "http://sports.hinet.net/2012olygame/print/award/print_award.php?";
					if (SEVER_API.equals("http://210.71.254.223")) {//正式機
						url = "http://sports.hinet.net/2012olygame/print/award/print_award.php?";
					}else{//測試機
						url = "http://sports.cms.hinet.net/2012olygame/print/award/print_award.php?";
					}
					Intent it = new Intent(Intent.ACTION_VIEW, Uri
							.parse(url + "sn=" + sn + "&type=1&gift_id=" + giftid + "&check=" + check));
					startActivity(it);
				} else if (quertPersonCouponDataOfKind.get(position).getGiftCode() == 2) {
					Intent it4 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
					startActivity(it4);
				} else if (quertPersonCouponDataOfKind.get(position).getGiftCode() == 3) {
					Intent it3 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://cheerspoint.unisurf.tw/"));
					startActivity(it3);
				} else if (quertPersonCouponDataOfKind.get(position).getGiftCode() == 4) {
					String url2 = "http://sports.hinet.net/2012olygame/print/gold/print_gold_sn.php?";
					if (SEVER_API.equals("http://210.71.254.223")) {//正式機
						url2 = "http://sports.hinet.net/2012olygame/print/gold/print_gold_sn.php?";
					}else{//測試機
						url2 = "http://sports.cms.hinet.net/2012olygame/print/gold/print_gold_sn.php?";
					}
					Intent it2 = new Intent(Intent.ACTION_VIEW, Uri.parse(url2 + "sn=" + sn + "&type=1&gift_id=" + giftid + "&check=" + check));
					startActivity(it2);
				} else if (quertPersonCouponDataOfKind.get(position).getGiftCode() == 6) {
					GetStoreInfoBean getStoreInfoBean = new GetStoreInfoBean();
					String url3 ;
					if (SEVER_API.equals("http://210.71.254.223")) {//正式機
						url3 = "http://sports.hinet.net/2012olygame/print/award/print_industry.php?";
					}else{//測試機
						url3 = "http://sports.cms.hinet.net/2012olygame/print/award/print_industry.php?";
					}
//					getStoreInfoBean.setUrl(url3 + "sn=" + sn + "&type=1&gift_id=" + giftid + "&check=" + check);//TODO 設定
					Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(url3 + "sn=" + sn + "&type=1&gift_id=" + giftid + "&check=" + check));
//					((Olympic) getApplicationContext()).setStoreInfoBean(getStoreInfoBean);
//					Bundle bundle = new Bundle();
//					bundle.putInt("type", 3);// 3為異業
//					Intent it = new Intent();
//					it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					it.putExtras(bundle);
//					it.setClass(TreeActivity.this,	GiftStoreInfoPageActivity.class);
					startActivity(it);
				} else {
					Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("http://210.71.254.223/olympic/event_infos"));
					startActivity(it);
				}
			}
		});
	}

}
